소스 검색

BUG修改

lin 4 년 전
부모
커밋
4cd4c2fa4b
56개의 변경된 파일1170개의 추가작업 그리고 112개의 파일을 삭제
  1. 14 0
      smart-city-intf/src/main/java/com/zcxk/smartcity/data/access/dto/ValveControlDataDto.java
  2. 3 0
      smart-city-intf/src/main/java/com/zcxk/smartcity/data/access/entity/Device.java
  3. 17 1
      smart-city-intf/src/main/java/com/zcxk/smartcity/data/access/service/impl/DeviceDataServiceV2Impl.java
  4. 2 0
      smart-city-intf/src/main/resources/mapper/DeviceMapper.xml
  5. 2 3
      smart-city-platform/src/main/java/com/bz/smart_city/async/AsyncInstallPlanDownloadTask.java
  6. 24 1
      smart-city-platform/src/main/java/com/bz/smart_city/commom/security/JwtAuthenticationTokenFilter.java
  7. 15 0
      smart-city-platform/src/main/java/com/bz/smart_city/commom/security/SecurityHandlerConfig.java
  8. 6 1
      smart-city-platform/src/main/java/com/bz/smart_city/commom/security/WebSecurityConfig.java
  9. 84 0
      smart-city-platform/src/main/java/com/bz/smart_city/commom/security/app/AppAuthenticationFilter.java
  10. 66 0
      smart-city-platform/src/main/java/com/bz/smart_city/commom/security/app/AppAuthenticationProvider.java
  11. 58 0
      smart-city-platform/src/main/java/com/bz/smart_city/commom/security/app/AppAuthenticationToken.java
  12. 45 0
      smart-city-platform/src/main/java/com/bz/smart_city/commom/security/app/AppDetailService.java
  13. 9 0
      smart-city-platform/src/main/java/com/bz/smart_city/commom/security/app/AppRequestData.java
  14. 53 0
      smart-city-platform/src/main/java/com/bz/smart_city/commom/security/app/AppSecurityConfig.java
  15. 125 0
      smart-city-platform/src/main/java/com/bz/smart_city/commom/security/app/AppSecurityHandlerConfig.java
  16. 77 0
      smart-city-platform/src/main/java/com/bz/smart_city/commom/security/app/AppUser.java
  17. 2 8
      smart-city-platform/src/main/java/com/bz/smart_city/commom/security/integration/IntegrationLoginAuthenticationFilter.java
  18. 24 0
      smart-city-platform/src/main/java/com/bz/smart_city/commom/util/JwtTokenUtil.java
  19. 44 0
      smart-city-platform/src/main/java/com/bz/smart_city/controller/ExternalApiController.java
  20. 9 8
      smart-city-platform/src/main/java/com/bz/smart_city/controller/water/WaterMeterReadController.java
  21. 4 2
      smart-city-platform/src/main/java/com/bz/smart_city/dao/BuildingMapper.java
  22. 2 2
      smart-city-platform/src/main/java/com/bz/smart_city/dao/ConcentratorMapper.java
  23. 14 0
      smart-city-platform/src/main/java/com/bz/smart_city/dao/ThirdPartyAppMapper.java
  24. 14 0
      smart-city-platform/src/main/java/com/bz/smart_city/dto/ValveControlDataDto.java
  25. 46 0
      smart-city-platform/src/main/java/com/bz/smart_city/entity/ThirdPartyApp.java
  26. 3 1
      smart-city-platform/src/main/java/com/bz/smart_city/excel/AbstractResolverExcelTemplate.java
  27. 2 4
      smart-city-platform/src/main/java/com/bz/smart_city/excel/download/CollectorDownloadExcelTemplate.java
  28. 1 1
      smart-city-platform/src/main/java/com/bz/smart_city/excel/download/ConcentratorDownloadExcelTemplate.java
  29. 3 3
      smart-city-platform/src/main/java/com/bz/smart_city/excel/download/GdDeviceDownloadExcelTemplate.java
  30. 1 4
      smart-city-platform/src/main/java/com/bz/smart_city/excel/download/GeneralDownloadExcelTemplate.java
  31. 1 1
      smart-city-platform/src/main/java/com/bz/smart_city/excel/download/WaterDownloadExcelTemplate.java
  32. 34 21
      smart-city-platform/src/main/java/com/bz/smart_city/excel/resolver/BuildingResolverExcelTemplate.java
  33. 1 1
      smart-city-platform/src/main/java/com/bz/smart_city/excel/resolver/CollectorResolveExcelTemplate.java
  34. 41 12
      smart-city-platform/src/main/java/com/bz/smart_city/excel/resolver/WaterDeviceResolverExcelTemplate.java
  35. 11 0
      smart-city-platform/src/main/java/com/bz/smart_city/service/ThirdPartyAppService.java
  36. 9 0
      smart-city-platform/src/main/java/com/bz/smart_city/service/ValveService.java
  37. 50 0
      smart-city-platform/src/main/java/com/bz/smart_city/service/impl/AppTokenServiceImpl.java
  38. 2 2
      smart-city-platform/src/main/java/com/bz/smart_city/service/impl/BuildingServiceImpl.java
  39. 1 1
      smart-city-platform/src/main/java/com/bz/smart_city/service/impl/ConcentratorCheckServiceImpl.java
  40. 2 2
      smart-city-platform/src/main/java/com/bz/smart_city/service/impl/ConcentratorServiceImpl.java
  41. 4 3
      smart-city-platform/src/main/java/com/bz/smart_city/service/impl/DeviceServiceImpl.java
  42. 2 2
      smart-city-platform/src/main/java/com/bz/smart_city/service/impl/DimensionServiceImpl.java
  43. 6 1
      smart-city-platform/src/main/java/com/bz/smart_city/service/impl/ImportServiceImpl.java
  44. 24 0
      smart-city-platform/src/main/java/com/bz/smart_city/service/impl/ThirdPartyAppServiceImpl.java
  45. 45 0
      smart-city-platform/src/main/java/com/bz/smart_city/service/impl/ValveServiceImpl.java
  46. 4 4
      smart-city-platform/src/main/java/com/bz/smart_city/service/impl/WaterRelatedDeviceServiceImpl.java
  47. 8 8
      smart-city-platform/src/main/java/com/bz/smart_city/service/importfile/AsyncTaskImportService.java
  48. 1 1
      smart-city-platform/src/main/java/com/bz/smart_city/service/udip/UdipEtlDataCommandService.java
  49. 10 0
      smart-city-platform/src/main/java/com/bz/smart_city/service/valve/DefaultValveControlProvider.java
  50. 7 0
      smart-city-platform/src/main/java/com/bz/smart_city/service/valve/ValveControlProvider.java
  51. BIN
      smart-city-platform/src/main/resources/excel/deviceTemplateV3.xlsx
  52. 15 5
      smart-city-platform/src/main/resources/mapper/BuildingMapper.xml
  53. 6 0
      smart-city-platform/src/main/resources/mapper/ConcentratorMapper.xml
  54. 2 7
      smart-city-platform/src/main/resources/mapper/MeterReadRecordMapper.xml
  55. 2 2
      smart-city-platform/src/main/resources/mapper/StatMeterReadRateByBuildingMapper.xml
  56. 113 0
      smart-city-platform/src/main/resources/mapper/ThirdPartyAppMapper.xml

+ 14 - 0
smart-city-intf/src/main/java/com/zcxk/smartcity/data/access/dto/ValveControlDataDto.java

@@ -0,0 +1,14 @@
+package com.zcxk.smartcity.data.access.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+public class ValveControlDataDto {
+
+    @ApiModelProperty("水表表号")
+    private String meterNo;
+
+    @ApiModelProperty("阀门操作,0 关,1 开")
+    private String valve;
+}

+ 3 - 0
smart-city-intf/src/main/java/com/zcxk/smartcity/data/access/entity/Device.java

@@ -89,4 +89,7 @@ public class Device {
     @ApiModelProperty(value = "设备类型名称")
     private String equipmentType ;
 
+    @ApiModelProperty(value = "水表电子号", position = 17)
+    private String waterMeterNo;
+
 }

+ 17 - 1
smart-city-intf/src/main/java/com/zcxk/smartcity/data/access/service/impl/DeviceDataServiceV2Impl.java

@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.zcxk.smartcity.data.access.common.RedisUtil;
 import com.zcxk.smartcity.data.access.dao.*;
 import com.zcxk.smartcity.data.access.dto.UdipUnitDataDTO;
+import com.zcxk.smartcity.data.access.dto.ValveControlDataDto;
 import com.zcxk.smartcity.data.access.entity.*;
 import com.zcxk.smartcity.data.access.protocol.model.MeasuringData;
 import com.zcxk.smartcity.data.access.service.DeviceDataServiceV2;
@@ -185,10 +186,25 @@ public class DeviceDataServiceV2Impl implements DeviceDataServiceV2 {
                     }else {
                         record.setValveStatus(0);
                     }
+                    //推送阀门状态至抄表平台
+                    if (device.getCustomerId() != null && device.getCustomerId() == 129) {
+                        ValveControlDataDto valveControlData = new ValveControlDataDto();
+                        valveControlData.setMeterNo(device.getWaterMeterNo());
+                        valveControlData.setValve(record.getValveStatus().toString());
+                    }
                 }
                 record.setStatus(1);
                 if (waterMeterErrorDays != null) {
-                    record.setValveButtonStatus(waterMeterErrorDays.getValveButtonStatus());
+                    if(record.getValveStatus() != null){
+                        if(record.getValveStatus() == 1){
+                            record.setValveButtonStatus(1);
+                        }else {
+                            record.setValveButtonStatus(0);
+                        }
+                    }else {
+
+                        record.setValveButtonStatus(waterMeterErrorDays.getValveButtonStatus());
+                    }
                 }else {
                     record.setValveButtonStatus(1);
                 }

+ 2 - 0
smart-city-intf/src/main/resources/mapper/DeviceMapper.xml

@@ -244,6 +244,8 @@
 			END AS is_card,
 				d.id,
 				d.device_no,
+				d.device_no,
+				d.water_meter_no,
 				d.device_type,
 				d.sys_id,
 				d.site_id,

+ 2 - 3
smart-city-platform/src/main/java/com/bz/smart_city/async/AsyncInstallPlanDownloadTask.java

@@ -3,6 +3,7 @@ package com.bz.smart_city.async;
 import com.alibaba.fastjson.JSON;
 import com.bz.smart_city.commom.locks.RedisLock;
 import com.bz.smart_city.commom.util.FileUtil;
+import com.bz.smart_city.commom.util.UserUtil;
 import com.bz.smart_city.commom.util.Util;
 import com.bz.smart_city.commom.util.ZipUtils;
 import com.bz.smart_city.dao.BuildingMapper;
@@ -17,13 +18,11 @@ import com.bz.smart_city.dto.assistant.InstallPlanDTO;
 import com.bz.smart_city.entity.Building;
 import com.bz.smart_city.entity.Community;
 import com.bz.smart_city.entity.Customer;
-import com.bz.smart_city.entity.Message;
 import com.bz.smart_city.entity.assistant.InstallList;
 import com.bz.smart_city.entity.assistant.InstallPlan;
 import com.bz.smart_city.service.CommunityService;
 import com.bz.smart_city.service.CustomerService;
 import com.bz.smart_city.service.MessageService;
-import com.bz.smart_city.service.assistant.InstallPlanService;
 import lombok.extern.slf4j.Slf4j;
 import org.jxls.common.Context;
 import org.jxls.util.JxlsHelper;
@@ -229,7 +228,7 @@ public class AsyncInstallPlanDownloadTask {
 
 
             //2、获取建筑列表数据
-            List<Building> buildingList = buildingMapper.findBySiteId(loginUser.getSiteId(),null);
+            List<Building> buildingList = buildingMapper.findBySiteId(loginUser.getSiteId(),null, UserUtil.getCustomerIds());
 
 
 

+ 24 - 1
smart-city-platform/src/main/java/com/bz/smart_city/commom/security/JwtAuthenticationTokenFilter.java

@@ -1,5 +1,7 @@
 package com.bz.smart_city.commom.security;
 
+import com.bz.smart_city.commom.security.app.AppAuthenticationToken;
+import com.bz.smart_city.commom.security.app.AppUser;
 import com.bz.smart_city.commom.security.assistant.MemberLoginAuthenticationToken;
 import com.bz.smart_city.commom.security.assistant.mobile.MpMobileLoginAuthenticationToken;
 import com.bz.smart_city.commom.security.assistant.openid.OpenidLoginAuthenticationToken;
@@ -12,6 +14,7 @@ import com.bz.smart_city.entity.Site;
 import com.bz.smart_city.service.assistant.AssistantUserTokenService;
 import com.bz.smart_city.service.assistant.MemberTokenService;
 import com.bz.smart_city.service.TokenService;
+import com.bz.smart_city.service.impl.AppTokenServiceImpl;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -41,6 +44,8 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
     @Autowired
     private AssistantUserTokenService assistantUserTokenService;
     @Autowired
+    private AppTokenServiceImpl appTokenService;
+    @Autowired
     private JwtTokenUtil jwtTokenUtil;
     @Value("${server.servlet.context-path}")
     private String contextPath;
@@ -74,7 +79,18 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
                     }
                 }
             }
-        }else {
+        } else if(StringUtils.countMatches(request.getRequestURI(),"/meter/valve") == 1){
+            if (authHeader != null && authHeader.startsWith(tokenHead)) {
+                String authToken = authHeader.substring(tokenHead.length());
+                if (SecurityContextHolder.getContext().getAuthentication() == null) {
+                    AppUser appUser = appTokenService.getLoginUser(authToken);
+                    if (appUser != null) {
+                        this.appLogin(request, response, appUser);
+                    }
+                }
+            }
+        }
+        else {
             //用户登录
             if (authHeader != null && authHeader.startsWith(tokenHead)) {
                 String authToken = authHeader.substring(tokenHead.length());
@@ -110,6 +126,13 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
         SecurityContextHolder.getContext().setAuthentication(authenticationToken);
     }
 
+    //第三方应用登录
+    private void appLogin(HttpServletRequest request, HttpServletResponse response, AppUser appUser) {
+        AppAuthenticationToken authenticationToken = new AppAuthenticationToken(appUser, null, appUser.getAuthorities());
+        authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
+        SecurityContextHolder.getContext().setAuthentication(authenticationToken);
+    }
+
     //人员登录
     private void memberLogin(HttpServletRequest request, HttpServletResponse response, LoginMember loginMember) {
         MemberLoginAuthenticationToken authenticationToken = new MemberLoginAuthenticationToken(loginMember, loginMember.getAuthorities());

+ 15 - 0
smart-city-platform/src/main/java/com/bz/smart_city/commom/security/SecurityHandlerConfig.java

@@ -177,6 +177,21 @@ public class SecurityHandlerConfig {
         };
     }
 
+    @Bean(name = "appAuthenticationEntryPoint")
+    public AuthenticationEntryPoint appAuthenticationEntryPoint() {
+        return new AuthenticationEntryPoint() {
+
+            @Override
+            public void commence(HttpServletRequest request, HttpServletResponse response,
+                                 AuthenticationException authException) throws IOException, ServletException {
+                response.setContentType("application/json;charset=UTF-8");
+                ObjectMapper objectMapper = new ObjectMapper();
+                ajaxMessage.setMsg(-406,"未认证");
+                response.getWriter().write(objectMapper.writeValueAsString(ajaxMessage));
+            }
+        };
+    }
+
     /**
      * 退出处理
      *

+ 6 - 1
smart-city-platform/src/main/java/com/bz/smart_city/commom/security/WebSecurityConfig.java

@@ -1,5 +1,6 @@
 package com.bz.smart_city.commom.security;
 
+import com.bz.smart_city.commom.security.app.AppSecurityConfig;
 import com.bz.smart_city.commom.security.assistant.MemberLoginSecurityConfig;
 import com.bz.smart_city.commom.security.assistant.mobile.MpMobileLoginSecurityConfig;
 import com.bz.smart_city.commom.security.assistant.openid.OpenidSecurityConfig;
@@ -77,6 +78,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
     private SmsCodeSecurityConfig smsCodeSecurityConfig;
     @Autowired
     private IntegrationSecurityConfig integrationSecurityConfig;
+    @Autowired
+    private AppSecurityConfig appSecurityConfig;
 
     @Bean
     public PasswordEncoder passwordEncoder() {
@@ -147,7 +150,9 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
                 .and()
                 .apply(smsCodeSecurityConfig)
                 .and()
-                .apply(integrationSecurityConfig);
+                .apply(integrationSecurityConfig)
+                .and()
+                .apply(appSecurityConfig);
 
     }
 

+ 84 - 0
smart-city-platform/src/main/java/com/bz/smart_city/commom/security/app/AppAuthenticationFilter.java

@@ -0,0 +1,84 @@
+package com.bz.smart_city.commom.security.app;
+
+import com.alibaba.fastjson.JSON;
+import com.bz.smart_city.commom.security.mobile.MobileLoginAuthenticationToken;
+import org.springframework.security.authentication.AuthenticationServiceException;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.AuthenticationException;
+import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter;
+import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
+import org.springframework.util.Assert;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.BufferedReader;
+import java.io.IOException;
+
+public class AppAuthenticationFilter extends AbstractAuthenticationProcessingFilter {
+
+    private boolean postOnly = true;
+
+    // ~ Constructors
+    // ===================================================================================================
+
+    public AppAuthenticationFilter() {
+        super(new AntPathRequestMatcher("/app/login", "POST"));
+    }
+
+    // ~ Methods
+    // ========================================================================================================
+
+    @Override
+    public Authentication attemptAuthentication(HttpServletRequest request,
+                                                HttpServletResponse response) throws AuthenticationException {
+        if (postOnly && !request.getMethod().equals("POST")) {
+            throw new AuthenticationServiceException(
+                    "Authentication method not supported: " + request.getMethod());
+        }
+
+
+
+        String json = getBody(request);
+        AppRequestData data = JSON.parseObject(json, AppRequestData.class);
+
+        String appId = "";
+        String appSecretKey = "";
+        if (data != null) {
+            appId = data.getAppId();
+            appSecretKey = data.getAppSecretKey();
+        }
+
+
+
+
+        AppAuthenticationToken authRequest = new AppAuthenticationToken(appId, appSecretKey);
+
+        // Allow subclasses to set the "details" property
+        setDetails(request, authRequest);
+
+        return this.getAuthenticationManager().authenticate(authRequest);
+    }
+
+
+
+
+    protected void setDetails(HttpServletRequest request, AppAuthenticationToken authRequest) {
+        authRequest.setDetails(authenticationDetailsSource.buildDetails(request));
+    }
+
+    private String getBody(HttpServletRequest request){
+        try {
+            BufferedReader br = request.getReader();
+            String str, wholeStr = "";
+            while((str = br.readLine()) != null){
+                wholeStr += str;
+            }
+            return wholeStr;
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+
+}

+ 66 - 0
smart-city-platform/src/main/java/com/bz/smart_city/commom/security/app/AppAuthenticationProvider.java

@@ -0,0 +1,66 @@
+package com.bz.smart_city.commom.security.app;
+
+import com.bz.smart_city.commom.security.mobile.MobileLoginAuthenticationToken;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.security.authentication.AuthenticationProvider;
+import org.springframework.security.authentication.BadCredentialsException;
+import org.springframework.security.authentication.InternalAuthenticationServiceException;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.AuthenticationException;
+import org.springframework.security.core.userdetails.UserDetails;
+import org.springframework.security.core.userdetails.UserDetailsService;
+import org.springframework.security.crypto.password.PasswordEncoder;
+import org.springframework.util.Assert;
+
+@Slf4j
+public class AppAuthenticationProvider implements AuthenticationProvider {
+
+    private UserDetailsService userDetailsService;
+
+    private PasswordEncoder passwordEncoder;
+
+    @Override
+    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
+        AppAuthenticationToken authenticationToken = (AppAuthenticationToken)authentication;
+        UserDetails userDetails = userDetailsService.loadUserByUsername((String) authenticationToken.getPrincipal());
+        if (userDetails == null) {
+            throw new InternalAuthenticationServiceException("无法获取用户信息");
+        }
+        String presentedPassword = authenticationToken.getCredentials().toString();
+
+
+        if (!StringUtils.equals(presentedPassword, userDetails.getPassword())) {
+            log.debug("Authentication failed: password does not match stored value");
+
+            throw new BadCredentialsException("应用密钥错误");
+        }
+        AppAuthenticationToken authenticationTokenReslut = new AppAuthenticationToken(userDetails,authenticationToken.getCredentials(),userDetails.getAuthorities());
+
+        authenticationTokenReslut.setDetails(authenticationToken.getDetails());
+
+        return authenticationTokenReslut;
+    }
+
+    @Override
+    public boolean supports(Class<?> authentication) {
+        return AppAuthenticationToken.class.isAssignableFrom(authentication);
+    }
+
+    public void setPasswordEncoder(PasswordEncoder passwordEncoder) {
+        Assert.notNull(passwordEncoder, "passwordEncoder cannot be null");
+        this.passwordEncoder = passwordEncoder;
+    }
+
+    protected PasswordEncoder getPasswordEncoder() {
+        return passwordEncoder;
+    }
+
+    public UserDetailsService getUserDetailsService() {
+        return userDetailsService;
+    }
+
+    public void setUserDetailsService(UserDetailsService userDetailsService) {
+        this.userDetailsService = userDetailsService;
+    }
+}

+ 58 - 0
smart-city-platform/src/main/java/com/bz/smart_city/commom/security/app/AppAuthenticationToken.java

@@ -0,0 +1,58 @@
+package com.bz.smart_city.commom.security.app;
+
+import org.springframework.security.authentication.AbstractAuthenticationToken;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.SpringSecurityCoreVersion;
+
+import java.util.Collection;
+
+
+public class AppAuthenticationToken extends AbstractAuthenticationToken {
+    private static final long serialVersionUID = SpringSecurityCoreVersion.SERIAL_VERSION_UID;
+
+
+    private final Object principal;
+    private Object credentials;
+
+
+    public AppAuthenticationToken(String mobile, Object credentials) {
+        super(null);
+        this.principal = mobile;
+        this.credentials = credentials;
+        setAuthenticated(false);
+    }
+
+    public AppAuthenticationToken(Object principal, Object credentials, Collection<? extends GrantedAuthority> authorities) {
+        super(authorities);
+        this.principal = principal;
+        this.credentials = credentials;
+        super.setAuthenticated(true);
+    }
+
+    @Override
+    public Object getCredentials() {
+        return this.credentials;
+    }
+
+    @Override
+    public Object getPrincipal() {
+        return this.principal;
+    }
+    /**
+     * @param isAuthenticated
+     * @throws IllegalArgumentException
+     */
+    @Override
+    public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
+        if (isAuthenticated) {
+            throw new IllegalArgumentException("Cannot set this token to trusted - use constructor which takes a GrantedAuthority list instead");
+        }
+        super.setAuthenticated(false);
+    }
+
+    @Override
+    public void eraseCredentials() {
+        super.eraseCredentials();
+    }
+
+}

+ 45 - 0
smart-city-platform/src/main/java/com/bz/smart_city/commom/security/app/AppDetailService.java

@@ -0,0 +1,45 @@
+package com.bz.smart_city.commom.security.app;
+
+import com.bz.smart_city.commom.security.validate.ValidateCodeException;
+import com.bz.smart_city.commom.util.ByteArrayUtils;
+import com.bz.smart_city.commom.util.RedisUtil;
+import com.bz.smart_city.dao.*;
+import com.bz.smart_city.dto.LoginUser;
+import com.bz.smart_city.dto.SiteUserDto;
+import com.bz.smart_city.entity.*;
+import com.bz.smart_city.service.PermissionService;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.authentication.DisabledException;
+import org.springframework.security.core.userdetails.UserDetails;
+import org.springframework.security.core.userdetails.UserDetailsService;
+import org.springframework.security.core.userdetails.UsernameNotFoundException;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static com.google.common.collect.Lists.newArrayList;
+
+@Component
+public class AppDetailService implements UserDetailsService {
+
+    @Autowired
+    private ThirdPartyAppMapper thirdPartyAppMapper;
+
+    @Override
+    public UserDetails loadUserByUsername(String appId) throws UsernameNotFoundException {
+        ThirdPartyApp app = thirdPartyAppMapper.findByAppId(appId);
+        if (app == null) {
+            throw new UsernameNotFoundException("该应用ID不存在");
+        }
+        AppUser appUser = new AppUser();
+        appUser.setAppId(app.getAppId());
+        appUser.setAppSecretKey(app.getAppSecretKey());
+        return appUser;
+    }
+
+
+}

+ 9 - 0
smart-city-platform/src/main/java/com/bz/smart_city/commom/security/app/AppRequestData.java

@@ -0,0 +1,9 @@
+package com.bz.smart_city.commom.security.app;
+
+import lombok.Data;
+
+@Data
+public class AppRequestData {
+    private String appId;
+    private String appSecretKey;
+}

+ 53 - 0
smart-city-platform/src/main/java/com/bz/smart_city/commom/security/app/AppSecurityConfig.java

@@ -0,0 +1,53 @@
+package com.bz.smart_city.commom.security.app;
+
+import com.bz.smart_city.commom.security.mobile.MobileLoginAuthenticationFilter;
+import com.bz.smart_city.commom.security.mobile.MobileLoginAuthenticationProvider;
+import com.bz.smart_city.commom.security.mobile.MobileLoginUserDetailService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.context.annotation.Bean;
+import org.springframework.security.authentication.AuthenticationManager;
+import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
+import org.springframework.security.config.annotation.web.builders.HttpSecurity;
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
+import org.springframework.security.crypto.password.PasswordEncoder;
+import org.springframework.security.web.AuthenticationEntryPoint;
+import org.springframework.security.web.DefaultSecurityFilterChain;
+import org.springframework.security.web.authentication.AuthenticationFailureHandler;
+import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
+import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
+import org.springframework.stereotype.Component;
+
+@Component
+public class AppSecurityConfig extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> {
+    @Autowired
+    @Qualifier("appAuthenticationSuccessHandler")
+    private AuthenticationSuccessHandler authenticationSuccessHandler;
+    @Autowired
+    @Qualifier("appAuthenticationFailureHandler")
+    private AuthenticationFailureHandler authenticationFailureHandler;
+    @Autowired
+    private AppDetailService userDetailsService;
+    @Autowired
+    @Qualifier("appAuthenticationEntryPoint")
+    private AuthenticationEntryPoint authenticationEntryPoint;
+
+
+
+    @Override
+    public void configure(HttpSecurity http) throws Exception {
+        AppAuthenticationFilter appAuthenticationFilter = new AppAuthenticationFilter();
+        appAuthenticationFilter.setAuthenticationManager(http.getSharedObject(AuthenticationManager.class));
+        appAuthenticationFilter.setAuthenticationSuccessHandler(authenticationSuccessHandler);
+        appAuthenticationFilter.setAuthenticationFailureHandler(authenticationFailureHandler);
+
+        AppAuthenticationProvider appAuthenticationProvider = new AppAuthenticationProvider();
+
+        appAuthenticationProvider.setUserDetailsService(userDetailsService);
+        //appAuthenticationProvider.setPasswordEncoder(passwordEncoder());
+        http.exceptionHandling().authenticationEntryPoint(authenticationEntryPoint)
+                .and()
+                .authenticationProvider(appAuthenticationProvider)
+                .addFilterAfter(appAuthenticationFilter, UsernamePasswordAuthenticationFilter.class);
+    }
+}

+ 125 - 0
smart-city-platform/src/main/java/com/bz/smart_city/commom/security/app/AppSecurityHandlerConfig.java

@@ -0,0 +1,125 @@
+package com.bz.smart_city.commom.security.app;
+
+import com.bz.smart_city.commom.model.AjaxMessage;
+import com.bz.smart_city.commom.model.ResultStatus;
+import com.bz.smart_city.commom.security.smsCode.SmsCodeException;
+import com.bz.smart_city.commom.security.validate.ValidateCodeException;
+import com.bz.smart_city.commom.util.JwtTokenUtil;
+import com.bz.smart_city.commom.util.RedisUtil;
+import com.bz.smart_city.commom.util.Util;
+import com.bz.smart_city.dto.LoginUser;
+import com.bz.smart_city.entity.LoginLogs;
+import com.bz.smart_city.entity.User;
+import com.bz.smart_city.service.LoginLogsService;
+import com.bz.smart_city.service.TokenService;
+import com.bz.smart_city.service.UserService;
+import com.bz.smart_city.service.impl.AppTokenServiceImpl;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.security.access.AccessDeniedException;
+import org.springframework.security.authentication.*;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.AuthenticationException;
+import org.springframework.security.core.userdetails.UsernameNotFoundException;
+import org.springframework.security.web.AuthenticationEntryPoint;
+import org.springframework.security.web.access.AccessDeniedHandler;
+import org.springframework.security.web.authentication.AuthenticationFailureHandler;
+import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
+import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.time.LocalDateTime;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * spring security处理器
+ */
+@Slf4j
+@Configuration
+public class AppSecurityHandlerConfig {
+
+    @Autowired
+    private AppTokenServiceImpl appTokenService;
+
+    private AjaxMessage ajaxMessage = new AjaxMessage();
+
+    /**
+     * 登陆成功,返回Token
+     *
+     * @return
+     */
+    @Bean(name = "appAuthenticationSuccessHandler")
+    public AuthenticationSuccessHandler userAuthenticationSuccessHandler() {
+        return new AuthenticationSuccessHandler() {
+
+            @Override
+            public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
+                                                Authentication authentication) throws IOException, ServletException {
+                response.setContentType("application/json;charset=UTF-8");
+
+                ObjectMapper objectMapper = new ObjectMapper();
+                AppUser appUser = (AppUser) authentication.getPrincipal();
+                String jwtToken = appTokenService.saveToken(appUser);
+                Map<String,String> map = new HashMap<>();
+                map.put("token",jwtToken);
+                ajaxMessage.setMsg(ResultStatus.OK, map);
+
+
+                response.getWriter().write(objectMapper.writeValueAsString(ajaxMessage));
+
+
+            }
+        };
+    }
+
+    /**
+     * 登陆失败
+     *
+     * @return
+     */
+    @Bean(name = "appAuthenticationFailureHandler")
+    public AuthenticationFailureHandler userAuthenticationFailureHandler() {
+        return new AuthenticationFailureHandler() {
+
+            @Override
+            public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
+                                                AuthenticationException exception) throws IOException, ServletException {
+                response.setContentType("application/json;charset=UTF-8");
+                ObjectMapper objectMapper = new ObjectMapper();
+                if (exception instanceof UsernameNotFoundException) {
+                    ajaxMessage.setMsg(ResultStatus.USERNAME_NOT_FOUND_ERROR);
+                }if (exception instanceof BadCredentialsException ) {
+                    ajaxMessage.setMsg(-103,exception.getMessage());
+                } else if (exception instanceof LockedException) {
+                    ajaxMessage.setMsg(ResultStatus.ACCOUNT_LOCKED_ERROR);
+                } else if (exception instanceof CredentialsExpiredException) {
+                    ajaxMessage.setMsg(ResultStatus.CREDENTIALS_EXPIRED_ERROR);
+                } else if (exception instanceof AccountExpiredException) {
+                    ajaxMessage.setMsg(ResultStatus.ACCOUNT_EXPIRED_ERROR);
+                } else if (exception instanceof DisabledException) {
+                    ajaxMessage.setMsg(ResultStatus.ACCOUNT_DISABLED_ERROR);
+                } else if (exception instanceof ValidateCodeException) {
+                    ajaxMessage.setMsg(-101, exception.getMessage());
+                }else if (exception instanceof SmsCodeException) {
+                    ajaxMessage.setMsg(-101, exception.getMessage());
+                } else {
+                    ajaxMessage.setMsg(-1, exception.getMessage());
+
+                }
+                response.getWriter().write(objectMapper.writeValueAsString(ajaxMessage));
+            }
+        };
+
+    }
+
+
+
+}

+ 77 - 0
smart-city-platform/src/main/java/com/bz/smart_city/commom/security/app/AppUser.java

@@ -0,0 +1,77 @@
+package com.bz.smart_city.commom.security.app;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.userdetails.UserDetails;
+
+import java.time.LocalDateTime;
+import java.util.Collection;
+
+
+public class AppUser implements UserDetails {
+
+    private String appId;
+    private String appSecretKey;
+
+    @JsonIgnore
+    private LocalDateTime expireTime;
+
+    @Override
+    public Collection<? extends GrantedAuthority> getAuthorities() {
+        return null;
+    }
+
+    @Override
+    public String getPassword() {
+        return appSecretKey;
+    }
+
+    @Override
+    public String getUsername() {
+        return appId;
+    }
+
+    @Override
+    public boolean isAccountNonExpired() {
+        return true;
+    }
+
+    @Override
+    public boolean isAccountNonLocked() {
+        return true;
+    }
+
+    @Override
+    public boolean isCredentialsNonExpired() {
+        return true;
+    }
+
+    @Override
+    public boolean isEnabled() {
+        return true;
+    }
+
+    public String getAppId() {
+        return appId;
+    }
+
+    public void setAppId(String appId) {
+        this.appId = appId;
+    }
+
+    public String getAppSecretKey() {
+        return appSecretKey;
+    }
+
+    public void setAppSecretKey(String appSecretKey) {
+        this.appSecretKey = appSecretKey;
+    }
+
+    public LocalDateTime getExpireTime() {
+        return expireTime;
+    }
+
+    public void setExpireTime(LocalDateTime expireTime) {
+        this.expireTime = expireTime;
+    }
+}

+ 2 - 8
smart-city-platform/src/main/java/com/bz/smart_city/commom/security/integration/IntegrationLoginAuthenticationFilter.java

@@ -15,12 +15,6 @@ import java.util.Base64;
 public class IntegrationLoginAuthenticationFilter extends AbstractAuthenticationProcessingFilter {
     // ~ Static fields/initializers
     // =====================================================================================
-
-    public static final String SPRING_SECURITY_FORM_SOURCE_KEY = "source";
-    public static final String SPRING_SECURITY_FORM_CODE_KEY = "code";
-
-    private String sourceParameter = SPRING_SECURITY_FORM_SOURCE_KEY;
-    private String codeParameter = SPRING_SECURITY_FORM_CODE_KEY;
     private boolean postOnly = true;
 
     // ~ Constructors
@@ -41,8 +35,8 @@ public class IntegrationLoginAuthenticationFilter extends AbstractAuthentication
                     "Authentication method not supported: " + request.getMethod());
         }
 
-        String source = request.getParameter(sourceParameter);
-        String code = request.getParameter(codeParameter);
+        String source = request.getParameter("source");
+        String code = request.getParameter("code");
 
         if (source == null) {
             source = "";

+ 24 - 0
smart-city-platform/src/main/java/com/bz/smart_city/commom/util/JwtTokenUtil.java

@@ -23,6 +23,7 @@ import io.jsonwebtoken.SignatureAlgorithm;
 @Component
 public class JwtTokenUtil implements Serializable {
     private static final String CLAIM_KEY_USERID = "sub";
+    private static final String CLAIM_KEY_APPID = "appId";
     private static final String CLAIM_KEY_CREATED = "created";
     private static final String CLAIM_KEY_LOGIN_TOKTN = "loginToken";
     private static final long serialVersionUID = -8305152446124853696L;
@@ -108,6 +109,17 @@ public class JwtTokenUtil implements Serializable {
         return generateToken(claims);
     }
 
+    /**
+     * 生成令牌
+     *
+     * @return 令牌
+     */
+    public String appToken(String id) {
+        Map<String, Object> claims = new HashMap<>();
+        claims.put(CLAIM_KEY_APPID, id);
+        return generateToken(claims);
+    }
+
     /**
      * 从令牌中获取用户id
      *
@@ -126,6 +138,18 @@ public class JwtTokenUtil implements Serializable {
         return userId;
     }
 
+    public String getAppIdFromToken(String token) {
+        String appId;
+        try {
+            Claims claims = getClaimsFromToken(token);
+            //userId = claims.getSubject();
+            appId = claims.get(CLAIM_KEY_APPID, String.class);
+        } catch (Exception e) {
+            appId = null;
+        }
+        return appId;
+    }
+
     /**
      * 判断令牌是否过期
      *

+ 44 - 0
smart-city-platform/src/main/java/com/bz/smart_city/controller/ExternalApiController.java

@@ -0,0 +1,44 @@
+package com.bz.smart_city.controller;
+
+
+import com.bz.smart_city.commom.model.AjaxMessage;
+import com.bz.smart_city.commom.model.ResultStatus;
+import com.bz.smart_city.dto.ValveControlDataDto;
+import com.bz.smart_city.dto.udip.CommandRspNotifyResult;
+import com.bz.smart_city.service.ValveService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.*;
+
+@Controller
+@ResponseBody
+@RequestMapping("meter")
+@Api(tags = "水表控制对外接口")
+public class ExternalApiController {
+
+    @Autowired
+    private ValveService valveService;
+
+    @ResponseBody
+    @GetMapping("valve/state")
+    @ApiOperation(value = "水表阀门控制")
+    public AjaxMessage valveState(
+            @ApiParam(value = "水表表号", required = true) @RequestParam(required = true) String meterNo
+    ) {
+        valveService.valveState(meterNo);
+        return new AjaxMessage(ResultStatus.OK);
+    }
+
+    @ResponseBody
+    @PostMapping("valve/control")
+    @ApiOperation(value = "水表阀门控制")
+    public AjaxMessage valveControl(
+            @ApiParam(value = "结果", required = true) @RequestBody(required = true) ValveControlDataDto result
+    ) {
+        valveService.valveControl(result);
+        return new AjaxMessage(ResultStatus.OK);
+    }
+}

+ 9 - 8
smart-city-platform/src/main/java/com/bz/smart_city/controller/water/WaterMeterReadController.java

@@ -345,7 +345,7 @@ public class WaterMeterReadController {
 	@GetMapping("/v2/queryUnReadDeviceList")
 	@ApiOperation(value = "场景下抄表率-统计未抄设备数据-适用于所有场景(新统计口径)")
 	public AjaxMessage<Pagination<DeviceDto>> queryUnReadDeviceList(
-			@ApiParam(value = "场景", required = true) @RequestParam(required = true) int channelId,
+			@ApiParam(value = "场景", required = false) @RequestParam(required = false) Integer channelId,
 			@ApiParam(value = "建筑", required = false) @RequestParam(required = false) Integer buildingId,
 			@ApiParam(value = "客户", required = false) @RequestParam(required = false) Integer customerId,
 			@ApiParam(value = "查询范围,2:昨天,7:近7日,15:近15日", required = true) @RequestParam(required = true) Integer period,
@@ -356,6 +356,7 @@ public class WaterMeterReadController {
 		condition.setBuildingId(buildingId);
 		condition.setPeriod(period);
 		condition.setCustormerId(customerId);
+		condition.setCustomerIds(UserUtil.getCustomerIds());
 		Pagination<DeviceDto> rtnList = statMeterReadRateByBuildingService.queryUnReadDeviceList(condition, pageNum,
 				pageSize);
 		return new AjaxMessage<Pagination<DeviceDto>>(ResultStatus.OK, rtnList);
@@ -386,7 +387,7 @@ public class WaterMeterReadController {
 	@GetMapping("/v2/getRateListByBuilding")
 	@ApiOperation(value = "场景下抄表率-按照建筑统计抄表率-适用于所有场景(新统计口径)")
 	public AjaxMessage<Pagination<StatMeterReadRateDto>> getRateListByBuilding(
-			@ApiParam(value = "场景", required = false) @RequestParam(required = false) int channelId,
+			@ApiParam(value = "场景", required = false) @RequestParam(required = false) Integer channelId,
 			@ApiParam(value = "小区", required = false) @RequestParam(required = false) Integer communityId,
 			@ApiParam(value = "客户Id", required = false) @RequestParam(required = false) Integer customerId,
 			@ApiParam(value = "建筑", required = false) @RequestParam(required = false) Integer buildingId,
@@ -423,7 +424,7 @@ public class WaterMeterReadController {
 	@GetMapping("/rateAreaList")
 	@ApiOperation(value = "获取抄表率区域列表")
 	public AjaxMessage<List<BuildingSelectDto>> rateAreaList(
-			@ApiParam(value = "场景", required = false) @RequestParam(required = false) int channelId,
+			@ApiParam(value = "场景", required = false) @RequestParam(required = false) Integer channelId,
 			@ApiParam(value = "小区", required = false) @RequestParam(required = false) Integer communityId,
 			@ApiParam(value = "客户Id", required = false) @RequestParam(required = false) Integer customerId,
 			@ApiParam(value = "建筑", required = false) @RequestParam(required = false) Integer buildingId,
@@ -454,7 +455,7 @@ public class WaterMeterReadController {
 	@GetMapping("/v2/getRateListByBuildingForNew")
 	@ApiOperation(value = "场景下抄表率-按照建筑统计抄表率-适用于新装水表(新统计口径)")
 	public AjaxMessage<Pagination<StatMeterReadRateDto>> getRateListByBuildingForNew(
-			@ApiParam(value = "场景", required = true) @RequestParam(required = true) int channelId,
+			@ApiParam(value = "场景", required = true) @RequestParam(required = true) Integer channelId,
 			@ApiParam(value = "小区", required = false) @RequestParam(required = false) Integer communityId,
 			@ApiParam(value = "客户Id", required = false) @RequestParam(required = false) Integer customerId,
 			@ApiParam(value = "建筑", required = false) @RequestParam(required = false) Integer buildingId,
@@ -491,7 +492,7 @@ public class WaterMeterReadController {
 //    @GetMapping("/getRateListByBuilding")
 //    @ApiOperation(value = "场景下抄表率-按照建筑统计抄表率-适用于所有场景")
 	public AjaxMessage<Pagination<StatMeterReadRateDto>> getRateListByBuilding(
-			@ApiParam(value = "场景", required = true) @RequestParam(required = true) int channelId,
+			@ApiParam(value = "场景", required = true) @RequestParam(required = true) Integer channelId,
 			@ApiParam(value = "开始时间,格式YYYYMMDD", required = false) @RequestParam(required = false) int startDate,
 			@ApiParam(value = "结束时间,格式YYYYMMDD", required = false) @RequestParam(required = false) int endDate,
 			@ApiParam(value = "客户", required = false) @RequestParam(required = false) Integer customerId,
@@ -534,7 +535,7 @@ public class WaterMeterReadController {
 	@GetMapping("/v2/summaryRateListByBuildingForNew")
 	@ApiOperation(value = "场景下抄表率-按照建筑汇总-适用于新装水表(新统计口径)")
 	public AjaxMessage<StatMeterReadRateDto> summaryRateListByBuildingForNew(
-			@ApiParam(value = "场景", required = true) @RequestParam(required = true) int channelId,
+			@ApiParam(value = "场景", required = false) @RequestParam(required = false) Integer channelId,
 			@ApiParam(value = "小区", required = false) @RequestParam(required = false) Integer communityId,
 			@ApiParam(value = "建筑", required = false) @RequestParam(required = false) Integer buildingId,
 			@ApiParam(value = "客户", required = false) @RequestParam(required = false) Integer customerId,
@@ -568,7 +569,7 @@ public class WaterMeterReadController {
 	@GetMapping("/v2/summaryRateListByBuilding")
 	@ApiOperation(value = "场景下抄表率-按照建筑汇总-适用于所有场景(新统计口径)")
 	public AjaxMessage<StatMeterReadRateDto> summaryRateListByBuilding(
-			@ApiParam(value = "场景", required = false) @RequestParam(required = false) int channelId,
+			@ApiParam(value = "场景", required = false) @RequestParam(required = false) Integer channelId,
 			@ApiParam(value = "小区", required = false) @RequestParam(required = false) Integer communityId,
 			@ApiParam(value = "建筑", required = false) @RequestParam(required = false) Integer buildingId,
 			@ApiParam(value = "客户", required = false) @RequestParam(required = false) Integer customerId,
@@ -643,7 +644,7 @@ public class WaterMeterReadController {
 	@GetMapping("/v2/exportRateListByBuilding")
 	@ApiOperation(value = "场景下抄表率-按照建筑导出-适用于所有场景(新统计口径)")
 	public void exportRateListByBuilding(
-			@ApiParam(value = "场景", required = true) @RequestParam(required = true) int channelId,
+			@ApiParam(value = "场景", required = true) @RequestParam(required = true) Integer channelId,
 			@ApiParam(value = "客户", required = false) @RequestParam(required = false) Integer customerId,
 			@ApiParam(value = "小区", required = false) @RequestParam(required = false) Integer communityId,
 			@ApiParam(value = "建筑", required = false) @RequestParam(required = false) Integer buildingId,

+ 4 - 2
smart-city-platform/src/main/java/com/bz/smart_city/dao/BuildingMapper.java

@@ -20,7 +20,7 @@ public interface BuildingMapper {
 
     int updateByPrimaryKeySelective(@Param("building") Building building);
 
-    List<Building> findBySiteId(@Param("siteId") Integer siteId, @Param("sysId") Integer sysId);
+    List<Building> findBySiteId(@Param("siteId") Integer siteId, @Param("sysId") Integer sysId, @Param("customerIds") List<Integer> customerIds);
 
     List<Building> findBySiteIdAndCustomerIds(@Param("siteId") Integer siteId, @Param("sysId") Integer sysId, @Param("customerIds") List<Integer> customerIds);
 
@@ -59,7 +59,7 @@ public interface BuildingMapper {
 
     List<BuildingInfoListDto> getBuildingStatistics(@Param("siteList") List<Integer> siteList, @Param("programItems") List<ProgramItem> programItems, @Param("sysId") Integer sysId, @Param("buildingId") String buildingId, @Param("buildingName") String buildingName, @Param("province") Integer province, @Param("city") Integer city, @Param("region") Integer region, @Param("community") Integer community, @Param("type") Integer type, @Param("longitudeMin") Double longitudeMin, @Param("longitudeMax") Double longitudeMax, @Param("latitudeMin") Double latitudeMin, @Param("latitudeMax") Double latitudeMax);
 
-    List<BuildingDto> getList(@Param("siteId") Integer siteId, @Param("buildingName") String buildingName);
+    List<BuildingDto> getList(@Param("siteId") Integer siteId, @Param("buildingName") String buildingName, @Param("customerIds") List<Integer> customerIds);
 
     Building getBuildingByDeviceId(@Param("deviceId") Long deviceId);
 
@@ -67,6 +67,8 @@ public interface BuildingMapper {
 
     Building findByName(@Param("siteId") Integer siteId, @Param("buildingName") String buildingName);
 
+    Building findByNameV2(@Param("siteId") Integer siteId, @Param("communityId") Integer communityId, @Param("buildingName") String buildingName);
+
     List<Building> findByIds(@Param("ids") List<Integer> ids);
 
     List<BuildingSelectInfoDto> deviceCountAreaList(@Param("siteId") Integer siteId, @Param("programItems") List<ProgramItem> programItems, @Param("sysId") Integer sysId, @Param("buildingId") Integer buildingId, @Param("deviceNo") String deviceNo, @Param("status") Integer status, @Param("manufacturerId") Integer manufacturerId, @Param("equipmentType") String equipmentType, @Param("model") String model, @Param("isTag") Integer isTag, @Param("floor") Integer floor, @Param("locDesc") String locDesc, @Param("province") Integer province, @Param("city") Integer city, @Param("region") Integer region, @Param("community") Integer community, @Param("concentratorNo") String concentratorNo, @Param("collectorNo") String collectorNo, @Param("errorType") String errorType, @Param("customerId") Integer customerId, @Param("days") Integer days, @Param("startDays") Integer startDays, @Param("endDays") Integer endDays, @Param("deviceTypeId") Integer deviceTypeId, @Param("valveStatus") Integer valveStatus, @Param("registerStatus") Integer registerStatus, @Param("issueStatus") Integer issueStatus, @Param("syncStatus") Integer syncStatus, @Param("startReading") Double startReading, @Param("endReading") Double endReading);

+ 2 - 2
smart-city-platform/src/main/java/com/bz/smart_city/dao/ConcentratorMapper.java

@@ -30,7 +30,7 @@ public interface ConcentratorMapper {
             @Param("buildingId") Integer buildingId,
             @Param("customerIds") List<Integer> customerIds);
 
-    List<ConcentratorDto> findList(@Param("siteId") Integer siteId, @Param("serialNumber") String serialNumber);
+    List<ConcentratorDto> findList(@Param("siteId") Integer siteId, @Param("serialNumber") String serialNumber, @Param("customerIds") List<Integer> customerIds);
 
     List<BuildingSelectInfoDto> getAreaList(
             @Param("siteId") Integer siteId,
@@ -42,7 +42,7 @@ public interface ConcentratorMapper {
 
     int findBySerialNumberUnique(@Param("id") Integer id, @Param("serialNumber") String serialNumber);
 
-    List<ConcentratorDto> getLazyList(@Param("siteId") Integer siteId);
+    List<ConcentratorDto> getLazyList(@Param("siteId") Integer siteId, @Param("customerIds") List<Integer> customerIds);
 
     Concentrator findName(@Param("siteId") Integer siteId, @Param("serialNumber") String serialNumber);
 

+ 14 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dao/ThirdPartyAppMapper.java

@@ -0,0 +1,14 @@
+package com.bz.smart_city.dao;
+
+import com.bz.smart_city.entity.ThirdPartyApp;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+@Mapper
+public interface ThirdPartyAppMapper {
+    int insertSelective(ThirdPartyApp record);
+
+    int updateByPrimaryKeySelective(ThirdPartyApp record);
+
+    ThirdPartyApp findByAppId(@Param("appId") String appId);
+}

+ 14 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dto/ValveControlDataDto.java

@@ -0,0 +1,14 @@
+package com.bz.smart_city.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+public class ValveControlDataDto {
+
+    @ApiModelProperty("水表表号")
+    private String meterNo;
+
+    @ApiModelProperty("阀门操作,0 关,1 开")
+    private String valve;
+}

+ 46 - 0
smart-city-platform/src/main/java/com/bz/smart_city/entity/ThirdPartyApp.java

@@ -0,0 +1,46 @@
+package com.bz.smart_city.entity;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import java.time.LocalDateTime;
+import lombok.Data;
+
+@ApiModel(value="com-bz-smart_city-entity-ThirdPartyApp")
+@Data
+public class ThirdPartyApp {
+    @ApiModelProperty(value="")
+    private Integer id;
+
+    /**
+    * 应用名称
+    */
+    @ApiModelProperty(value="应用名称")
+    private String name;
+
+    /**
+    * 应用id
+    */
+    @ApiModelProperty(value="应用id")
+    private String appId;
+
+    /**
+    * 应用密钥
+    */
+    @ApiModelProperty(value="应用密钥")
+    private String appSecretKey;
+
+    @ApiModelProperty(value="")
+    private Integer status;
+
+    @ApiModelProperty(value="")
+    private String createBy;
+
+    @ApiModelProperty(value="")
+    private LocalDateTime createDate;
+
+    @ApiModelProperty(value="")
+    private String updateBy;
+
+    @ApiModelProperty(value="")
+    private LocalDateTime updateDate;
+}

+ 3 - 1
smart-city-platform/src/main/java/com/bz/smart_city/excel/AbstractResolverExcelTemplate.java

@@ -42,6 +42,7 @@ public abstract class AbstractResolverExcelTemplate {
     @Autowired
     private ImportService importService;
 
+    protected Integer customerId;
     protected Integer sysId;
     protected Import record;
     protected Workbook workbook;
@@ -53,9 +54,10 @@ public abstract class AbstractResolverExcelTemplate {
     protected AtomicInteger failTime = new AtomicInteger(0);
 
 
-    public void resolver(Integer sysId, Import record, String messageTitle){
+    public void resolver(Integer sysId, Integer customerId, Import record, String messageTitle){
 
         this.sysId = sysId;
+        this.customerId = customerId;
         this.record = record;
         //this.workbook = workbook;
         this.messageContent = new StringBuffer();

+ 2 - 4
smart-city-platform/src/main/java/com/bz/smart_city/excel/download/CollectorDownloadExcelTemplate.java

@@ -4,9 +4,7 @@ import com.bz.smart_city.commom.util.UserUtil;
 import com.bz.smart_city.commom.util.Util;
 import com.bz.smart_city.dao.BuildingMapper;
 import com.bz.smart_city.dao.ConcentratorMapper;
-import com.bz.smart_city.dao.DeviceTypeMapper;
 import com.bz.smart_city.dto.ConcentratorDto;
-import com.bz.smart_city.dto.DeviceTypeDto;
 import com.bz.smart_city.dto.LoginUser;
 import com.bz.smart_city.entity.Building;
 import com.bz.smart_city.entity.Customer;
@@ -52,7 +50,7 @@ public class CollectorDownloadExcelTemplate extends AbstractDownloadExcelTemplat
 
 
         //获取建筑列表数据
-        List<Building> buildingList = buildingMapper.findBySiteId(loginUser.getSiteId(), null);
+        List<Building> buildingList = buildingMapper.findBySiteId(loginUser.getSiteId(), null, UserUtil.getCustomerIds());
         buildingList.forEach(building -> {
             if (building.getUnderFloorNum() != null) {
                 building.setUnderFloorNum(-building.getUnderFloorNum());
@@ -72,7 +70,7 @@ public class CollectorDownloadExcelTemplate extends AbstractDownloadExcelTemplat
         List<Customer> customerList = customerService.getCustomerList(loginUser.getSiteId());
 
         //获取集中器数据和采集器数据
-        List<ConcentratorDto> concentratorList = concentratorMapper.findList(loginUser.getSiteId(),null);
+        List<ConcentratorDto> concentratorList = concentratorMapper.findList(loginUser.getSiteId(),null, UserUtil.getCustomerIds());
 
         this.context = new Context();
         this.context.putVar("buildingList", buildingList);

+ 1 - 1
smart-city-platform/src/main/java/com/bz/smart_city/excel/download/ConcentratorDownloadExcelTemplate.java

@@ -50,7 +50,7 @@ public class ConcentratorDownloadExcelTemplate extends AbstractDownloadExcelTemp
 
 
         //获取建筑列表数据
-        List<Building> buildingList = buildingMapper.findBySiteId(loginUser.getSiteId(), null);
+        List<Building> buildingList = buildingMapper.findBySiteId(loginUser.getSiteId(), null, UserUtil.getCustomerIds());
         buildingList.forEach(building -> {
             if (building.getUnderFloorNum() != null) {
                 building.setUnderFloorNum(-building.getUnderFloorNum());

+ 3 - 3
smart-city-platform/src/main/java/com/bz/smart_city/excel/download/GdDeviceDownloadExcelTemplate.java

@@ -47,11 +47,11 @@ public class GdDeviceDownloadExcelTemplate extends AbstractDownloadExcelTemplate
         LoginUser loginUser = UserUtil.getCurrentUser();
         filePath = getFilePath();
         templatePath = "excel/gdDeviceTemplate20200914.xlsx";
-        downloadName = "光电直读表批量导入模板";
+        downloadName = "远传水表批量导入模板";
 
 
         //获取建筑列表数据
-        List<Building> buildingList = buildingMapper.findBySiteId(loginUser.getSiteId(), null);
+        List<Building> buildingList = buildingMapper.findBySiteId(loginUser.getSiteId(), null, UserUtil.getCustomerIds());
         buildingList.forEach(building -> {
             if (building.getUnderFloorNum() != null) {
                 building.setUnderFloorNum(-building.getUnderFloorNum());
@@ -73,7 +73,7 @@ public class GdDeviceDownloadExcelTemplate extends AbstractDownloadExcelTemplate
         List<Customer> customerList = customerService.getCustomerList(loginUser.getSiteId());
 
         //获取集中器数据和采集器数据
-        List<ConcentratorDto> concentratorList = concentratorMapper.getLazyList(loginUser.getSiteId());
+        List<ConcentratorDto> concentratorList = concentratorMapper.getLazyList(loginUser.getSiteId(),UserUtil.getCustomerIds());
 
         context = new Context();
         context.putVar("buildingList", buildingList);

+ 1 - 4
smart-city-platform/src/main/java/com/bz/smart_city/excel/download/GeneralDownloadExcelTemplate.java

@@ -9,11 +9,8 @@ import com.bz.smart_city.dto.DeviceTypeDto;
 import com.bz.smart_city.dto.LoginUser;
 import com.bz.smart_city.entity.Building;
 import com.bz.smart_city.entity.Channel;
-import com.bz.smart_city.entity.Customer;
 import com.bz.smart_city.excel.AbstractDownloadExcelTemplate;
-import com.bz.smart_city.service.CustomerService;
 import org.jxls.common.Context;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
@@ -50,7 +47,7 @@ public class GeneralDownloadExcelTemplate extends AbstractDownloadExcelTemplate
 
 
         //获取建筑列表数据
-        List<Building> buildingList = buildingMapper.findBySiteId(loginUser.getSiteId(), null);
+        List<Building> buildingList = buildingMapper.findBySiteId(loginUser.getSiteId(), null, UserUtil.getCustomerIds());
         buildingList.forEach(building -> {
             if (building.getUnderFloorNum() != null) {
                 building.setUnderFloorNum(-building.getUnderFloorNum());

+ 1 - 1
smart-city-platform/src/main/java/com/bz/smart_city/excel/download/WaterDownloadExcelTemplate.java

@@ -52,7 +52,7 @@ public class WaterDownloadExcelTemplate extends AbstractDownloadExcelTemplate {
 
 
         //获取建筑列表数据
-        List<Building> buildingList = buildingMapper.findBySiteId(loginUser.getSiteId(), null);
+        List<Building> buildingList = buildingMapper.findBySiteId(loginUser.getSiteId(), null, UserUtil.getCustomerIds());
         buildingList.forEach(building -> {
             if (building.getUnderFloorNum() != null) {
                 building.setUnderFloorNum(-building.getUnderFloorNum());

+ 34 - 21
smart-city-platform/src/main/java/com/bz/smart_city/excel/resolver/BuildingResolverExcelTemplate.java

@@ -63,35 +63,24 @@ public class BuildingResolverExcelTemplate extends AbstractResolverExcelTemplate
                     Cell communityNameCell = row.getCell(7);
                     Cell addressCell = row.getCell(8);
                     Cell c_remark = row.getCell(9);
+
+                    addressCell.setCellType(CellType.STRING);
+
                     if (buildingNameCell == null || StringUtils.equals("", buildingNameCell.getStringCellValue())) {
                         continue;
                     }
-                    //查询小区是否存在
-                    String communityName = communityNameCell.getStringCellValue();
-                    Community community = communityService.findByName(record.getSiteId(), communityName);
-                    //查询建筑是否存在
-                    Building buildingResult = buildingMapper.findByName(record.getSiteId(), buildingNameCell.getStringCellValue());
-                    if (buildingResult != null) {
-                        failTime.incrementAndGet();
-                        c_remark.setCellValue("该建筑名称已存在");
-                        continue;
-                    }
                     CellValue cellValueProvince = evaluator.evaluate(provinceCell);
                     CellValue cellValueCity = evaluator.evaluate(cityCell);
                     CellValue cellValueRegion = evaluator.evaluate(regionCell);
 
+                    Integer province =  (int) cellValueProvince.getNumberValue();
+                    Integer city =  (int) cellValueCity.getNumberValue();
+                    Integer region =  (int) cellValueRegion.getNumberValue();
+
                     Building building = new Building();
-                    building.setSiteId(record.getSiteId());
-                    building.setName(buildingNameCell.getStringCellValue());
-                    building.setAddress(addressCell.getStringCellValue());
-                    building.setProvince((int) cellValueProvince.getNumberValue());
-                    building.setCity((int) cellValueCity.getNumberValue());
-                    building.setRegion((int) cellValueRegion.getNumberValue());
-                    building.setStatus(1);
-                    building.setCreateBy("system");
-                    building.setUpdateBy("system");
-                    building.setCreateDate(LocalDateTime.now());
-                    building.setUpdateDate(LocalDateTime.now());
+                    //查询小区是否存在
+                    String communityName = communityNameCell.getStringCellValue();
+                    Community community = communityService.findByNameV2(record.getSiteId(), province, city, region, communityName);
                     if (community != null) {
                         building.setCommunity(community.getId());
                     } else {
@@ -110,15 +99,39 @@ public class BuildingResolverExcelTemplate extends AbstractResolverExcelTemplate
 
                         }
                         communityNew.setCode(code);
+                        communityNew.setCustomerId(customerId);
                         communityNew.setSiteId(record.getSiteId());
                         communityNew.setName(communityName);
                         communityNew.setProvince((int) cellValueProvince.getNumberValue());
                         communityNew.setCity((int) cellValueCity.getNumberValue());
                         communityNew.setRegion((int) cellValueRegion.getNumberValue());
                         communityNew.setStatus(1);
+                        communityNew.setAddress(addressCell.getStringCellValue());
                         communityService.insert(communityNew);
                         building.setCommunity(communityNew.getId());
                     }
+                    //查询建筑是否存在
+                    Building buildingResult = buildingMapper.findByNameV2(record.getSiteId(),building.getCommunity(), buildingNameCell.getStringCellValue());
+                    if (buildingResult != null) {
+                        failTime.incrementAndGet();
+                        c_remark.setCellValue("该建筑名称已存在");
+                        continue;
+                    }
+
+
+
+                    building.setSiteId(record.getSiteId());
+                    building.setName(buildingNameCell.getStringCellValue());
+                    building.setAddress(addressCell.getStringCellValue());
+                    building.setProvince(province);
+                    building.setCity(city);
+                    building.setRegion(region);
+                    building.setStatus(1);
+                    building.setCreateBy("system");
+                    building.setUpdateBy("system");
+                    building.setCreateDate(LocalDateTime.now());
+                    building.setUpdateDate(LocalDateTime.now());
+
                     log.info("begin building"+buildingNameCell.getStringCellValue()+" geo");
                     GeoDTO geoDTO = geoService.getBuildingInfo(cityNameCell.getStringCellValue(), communityName, buildingNameCell.getStringCellValue());
                     if (geoDTO != null) {

+ 1 - 1
smart-city-platform/src/main/java/com/bz/smart_city/excel/resolver/CollectorResolveExcelTemplate.java

@@ -119,7 +119,7 @@ public class CollectorResolveExcelTemplate extends AbstractResolverExcelTemplate
                     Concentrator concentrator = concentratorService.findCacheByName(record.getSiteId(),concentratorNameCell.getStringCellValue().trim());
                     if (concentrator == null) {
                         failTime.incrementAndGet();
-                        remarkCell.setCellValue(ResultStatus.BUILDING_IS_NOT_EXISTED.getMessage());
+                        remarkCell.setCellValue(ResultStatus.CONCENTRATOR_IS_NOT_EXISTED.getMessage());
                         continue;
                     }
 

+ 41 - 12
smart-city-platform/src/main/java/com/bz/smart_city/excel/resolver/WaterDeviceResolverExcelTemplate.java

@@ -69,6 +69,11 @@ public class WaterDeviceResolverExcelTemplate extends AbstractResolverExcelTempl
                     Cell floorCell = row.getCell(10);
                     Cell c_remark = row.getCell(11);
 
+                    buildingNameCell.setCellType(CellType.STRING);
+                    deviceNoCell.setCellType(CellType.STRING);
+                    deviceTypeNameCell.setCellType(CellType.STRING);
+                    locDescCell.setCellType(CellType.STRING);
+
                     if (StringUtils.equals("", buildingNameCell.getStringCellValue()) &&
                             StringUtils.equals("", deviceNoCell.getStringCellValue()) &&
                             StringUtils.equals("", deviceTypeNameCell.getStringCellValue()) &&
@@ -106,10 +111,24 @@ public class WaterDeviceResolverExcelTemplate extends AbstractResolverExcelTempl
                     device.setId(idWorker.nextId());
                     device.setSysId(sysId);
                     device.setSiteId(record.getSiteId());
-                    CellValue cellValuesetBuildingId = evaluator.evaluate(buildingIdCell);
-                    device.setBuildingId((int) cellValuesetBuildingId.getNumberValue());
-                    CellValue cellValueDeviceTypeId = evaluator.evaluate(deviceTypeIdCell);
-                    device.setDeviceType((int) cellValueDeviceTypeId.getNumberValue());
+                    try {
+                        CellValue cellValuesetBuildingId = evaluator.evaluate(buildingIdCell);
+                        device.setBuildingId((int) cellValuesetBuildingId.getNumberValue());
+                    } catch (Exception e){
+                        failTime.incrementAndGet();
+                        c_remark.setCellValue("建筑名称匹配错误");
+                        continue;
+                    }
+
+                    try {
+                        CellValue cellValueDeviceTypeId = evaluator.evaluate(deviceTypeIdCell);
+                        device.setDeviceType((int) cellValueDeviceTypeId.getNumberValue());
+                    }catch (Exception e){
+                        failTime.incrementAndGet();
+                        c_remark.setCellValue("设备类型匹配错误");
+                        continue;
+                    }
+
                     String deviceNo = StringUtils.lowerCase(deviceNoCell.getStringCellValue().trim());
                     int deviceNoResult = deviceMapper.findByDeviceNoUnique(null, deviceNo);
                     if (deviceNoResult > 0) {
@@ -127,20 +146,30 @@ public class WaterDeviceResolverExcelTemplate extends AbstractResolverExcelTempl
                         device.setFloor((int) floorCell.getNumericCellValue());
                     }
                     if (customerIdCell != null) {
-                        CellValue cellValuesetCustomerId = evaluator.evaluate(customerIdCell);
-                        device.setCustomerId((int) cellValuesetCustomerId.getNumberValue());
+                        try {
+                            CellValue cellValuesetCustomerId = evaluator.evaluate(customerIdCell);
+                            device.setCustomerId((int) cellValuesetCustomerId.getNumberValue());
+                        }catch (Exception e){
+                            failTime.incrementAndGet();
+                            c_remark.setCellValue("客户匹配错误");
+                            continue;
+                        }
+
                     }
                     if (waterMeterNoCell != null) {
                         //设置单元格类型
                         waterMeterNoCell.setCellType(CellType.STRING);
                         String waterMeterNo = StringUtils.lowerCase(waterMeterNoCell.getStringCellValue().trim());
-                        int waterMeterNoResult = deviceMapper.findByWaterMeterNoUnique(null, waterMeterNo);
-                        if (waterMeterNoResult > 0) {
-                            failTime.incrementAndGet();
-                            c_remark.setCellValue("水表电子号已存在");
-                            continue;
+                        if (!StringUtils.equals("", waterMeterNo)) {
+                            int waterMeterNoResult = deviceMapper.findByWaterMeterNoUnique(null, waterMeterNo);
+                            if (waterMeterNoResult > 0) {
+                                failTime.incrementAndGet();
+                                c_remark.setCellValue("水表电子号已存在");
+                                continue;
+                            }
+                            device.setWaterMeterNo(waterMeterNo);
                         }
-                        device.setWaterMeterNo(waterMeterNo);
+
                     }
                     if (waterMeterFileNoCell != null) {
                         waterMeterFileNoCell.setCellType(CellType.STRING);

+ 11 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/ThirdPartyAppService.java

@@ -0,0 +1,11 @@
+package com.bz.smart_city.service;
+
+import com.bz.smart_city.entity.ThirdPartyApp;
+public interface ThirdPartyAppService{
+
+
+    int insertSelective(ThirdPartyApp record);
+
+    int updateByPrimaryKeySelective(ThirdPartyApp record);
+
+}

+ 9 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/ValveService.java

@@ -0,0 +1,9 @@
+package com.bz.smart_city.service;
+
+import com.bz.smart_city.dto.ValveControlDataDto;
+
+public interface ValveService {
+    void valveState(String meterNo);
+
+    void valveControl(ValveControlDataDto result);
+}

+ 50 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/AppTokenServiceImpl.java

@@ -0,0 +1,50 @@
+package com.bz.smart_city.service.impl;
+
+import com.bz.smart_city.commom.security.app.AppUser;
+import com.bz.smart_city.commom.util.JwtTokenUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Primary;
+import org.springframework.stereotype.Service;
+
+import java.time.LocalDateTime;
+import java.util.UUID;
+
+
+@Primary
+@Service
+public class AppTokenServiceImpl {
+    @Autowired
+    private JwtTokenUtil jwtTokenUtil;
+
+    private  static final Long expiration = 3600L;
+
+
+    public String saveToken(AppUser appUser) {
+
+
+        appUser.setExpireTime(LocalDateTime.now().plusSeconds(expiration));
+
+        return jwtTokenUtil.appToken(appUser.getAppId());
+    }
+
+
+
+
+
+    public AppUser getLoginUser(String token) {
+
+        boolean is = jwtTokenUtil.isTokenExpired(token);
+        if (!is){
+            String appId = jwtTokenUtil.getAppIdFromToken(token);
+            if (appId != null) {
+                AppUser appUser = new AppUser();
+                appUser.setAppId(appId);
+                return appUser;
+            }
+
+        }
+        return null;
+    }
+
+
+}

+ 2 - 2
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/BuildingServiceImpl.java

@@ -250,7 +250,7 @@ public class BuildingServiceImpl implements BuildingService {
         List<Integer> ids = newArrayList();
         List<Integer> communityIds = newArrayList();
         List<BuildingSelectDto> buildingSelectDtoArrayList = newArrayList();
-        List<Building> buildingList = buildingMapper.findBySiteId(loginUser.getSiteId(), channelId);
+        List<Building> buildingList = buildingMapper.findBySiteId(loginUser.getSiteId(), channelId, UserUtil.getCustomerIds());
         if (buildingList != null && buildingList.size() > 0) {
             buildingList.forEach(building -> {
                 ids.add(building.getProvince());
@@ -1187,7 +1187,7 @@ public class BuildingServiceImpl implements BuildingService {
     @Override
     public List<BuildingDto> getBuildingList(String buildingName) {
         LoginUser loginUser = UserUtil.getCurrentUser();
-        return buildingMapper.getList(loginUser.getSiteId(), buildingName);
+        return buildingMapper.getList(loginUser.getSiteId(), buildingName, UserUtil.getCustomerIds());
     }
 
     @Override

+ 1 - 1
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/ConcentratorCheckServiceImpl.java

@@ -57,7 +57,7 @@ public class ConcentratorCheckServiceImpl implements ConcentratorCheckService{
         message.setSiteId(loginUser.getSiteId());
         message.setUserId(loginUser.getId());
         message.setMessageType(5);
-        message.setMessageTitle("光电直读表-集中器列表-档案校验");
+        message.setMessageTitle("远传水表-集中器列表-档案校验");
         message.setMessageContent("集中器"+concentrator.getSerialNumber()+"档案校验"+resultName+"。");
         message.setRead(0);
         messageService.insertSelective(message);

+ 2 - 2
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/ConcentratorServiceImpl.java

@@ -72,7 +72,7 @@ public class ConcentratorServiceImpl implements ConcentratorService{
     public List<ConcentratorDto> getList(String serialNumber) {
         LoginUser loginUser = new LoginUser();
         List<ConcentratorDto> list = concentratorMapper.findList(
-                loginUser.getSiteId(),serialNumber);
+                loginUser.getSiteId(),serialNumber,UserUtil.getCustomerIds());
         return list;
     }
 
@@ -193,7 +193,7 @@ public class ConcentratorServiceImpl implements ConcentratorService{
 
     @Override
     public void test() {
-        List<ConcentratorDto> list = concentratorMapper.findList(1,null);
+        List<ConcentratorDto> list = concentratorMapper.findList(1,null, UserUtil.getCustomerIds());
         for (ConcentratorDto concentratorDto : list) {
            Building building =  waterRelatedDeviceMapper.getConcentratorId(concentratorDto.getId());
             if (building != null) {

+ 4 - 3
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/DeviceServiceImpl.java

@@ -1423,12 +1423,12 @@ public  class DeviceServiceImpl implements DeviceService {
         else if(StringUtils.equals("hengxin-nb",deviceTypeDto.getEnModel()))
         {
             valveCommandRequest.setMeterCode(device.getWaterMeterNo());
-            udipEtlDataCommandService.commandSendV2(device.getUdipId(),valveCommandRequest);
+            udipEtlDataCommandService.defaultCommandSend(device.getUdipId(),valveCommandRequest);
         }
         else if(StringUtils.equals("ningbo-nb",deviceTypeDto.getEnModel()))
         {
             valveCommandRequest.setMeterCode(device.getWaterMeterNo());
-            JSONObject commandResult = udipEtlDataCommandService.commandSendV2(device.getUdipId(),valveCommandRequest);
+            JSONObject commandResult = udipEtlDataCommandService.defaultCommandSend(device.getUdipId(),valveCommandRequest);
 
             //2、插入开关阀门记录
             DeviceValveRecord deviceValveRecord = new DeviceValveRecord();
@@ -1455,7 +1455,8 @@ public  class DeviceServiceImpl implements DeviceService {
                 deviceValveRecordService.insertSelective(deviceValveRecord);
             }
         }else {
-
+            valveCommandRequest.setMeterCode(device.getWaterMeterNo());
+            udipEtlDataCommandService.defaultCommandSend(device.getUdipId(),valveCommandRequest);
         }
 
 

+ 2 - 2
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/DimensionServiceImpl.java

@@ -127,7 +127,7 @@ public class DimensionServiceImpl implements DimensionService{
 
         DimensionDataDto dimensionDataDto = new DimensionDataDto();
         //查询该站点的全部建筑
-        List<BuildingDto> buildingList = buildingMapper.getList(loginUser.getSiteId(), null);
+        List<BuildingDto> buildingList = buildingMapper.getList(loginUser.getSiteId(), null,UserUtil.getCustomerIds());
 
 
         List<DimensionDataItemDto> provinceList = newArrayList();
@@ -174,7 +174,7 @@ public class DimensionServiceImpl implements DimensionService{
         }
 
         //小区
-        List<CommunityDto> communityAreaList = communityMapper.findBySiteId(loginUser.getSiteId(), null);
+        List<CommunityDto> communityAreaList = communityMapper.findBySiteId(loginUser.getSiteId(), UserUtil.getCustomerIds());
         if (communityAreaList != null && communityAreaList.size() > 0) {
             communityAreaList.forEach(community -> {
                 DimensionDataItemDto build = new DimensionDataItemDto();

+ 6 - 1
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/ImportServiceImpl.java

@@ -101,7 +101,12 @@ public class ImportServiceImpl implements ImportService{
             asyncTaskImportService.executeAsyncDeviceTask(record,sysId);
         }
         if(importType == 3){
-            asyncTaskImportService.executeAsyncBuildingTask(record,file);
+            Integer customerId = null;
+            List<Integer> list = UserUtil.getCustomerIds();
+            if (list != null && list.size()==1) {
+                customerId = list.get(0);
+            }
+            asyncTaskImportService.executeAsyncBuildingTask(record,customerId,file);
         }
         if(importType == 4){
             //批量开户

+ 24 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/ThirdPartyAppServiceImpl.java

@@ -0,0 +1,24 @@
+package com.bz.smart_city.service.impl;
+
+import org.springframework.stereotype.Service;
+import javax.annotation.Resource;
+import com.bz.smart_city.entity.ThirdPartyApp;
+import com.bz.smart_city.dao.ThirdPartyAppMapper;
+import com.bz.smart_city.service.ThirdPartyAppService;
+@Service
+public class ThirdPartyAppServiceImpl implements ThirdPartyAppService{
+
+    @Resource
+    private ThirdPartyAppMapper thirdPartyAppMapper;
+
+    @Override
+    public int insertSelective(ThirdPartyApp record) {
+        return thirdPartyAppMapper.insertSelective(record);
+    }
+
+    @Override
+    public int updateByPrimaryKeySelective(ThirdPartyApp record) {
+        return thirdPartyAppMapper.updateByPrimaryKeySelective(record);
+    }
+
+}

+ 45 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/ValveServiceImpl.java

@@ -0,0 +1,45 @@
+package com.bz.smart_city.service.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.bz.smart_city.commom.exception.ServiceException;
+import com.bz.smart_city.dao.DeviceMapper;
+import com.bz.smart_city.dto.ValveControlDataDto;
+import com.bz.smart_city.service.DeviceService;
+import com.bz.smart_city.service.ValveService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Slf4j
+@Service
+public class ValveServiceImpl implements ValveService {
+
+    @Autowired
+    private DeviceMapper deviceMapper;
+    @Autowired
+    private DeviceService deviceService;
+
+    @Override
+    public void valveState(String meterNo) {
+        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
+        System.out.println(authentication);
+    }
+
+    @Override
+    public void valveControl(ValveControlDataDto result) {
+        log.info("begin valveControl result = {}", JSON.toJSONString(result));
+        List<Long> list = deviceMapper.findDeviceIdByWaterMeterNo(null,result.getMeterNo());
+        if (list == null || list.size() == 0) {
+            throw new ServiceException(-900,"该水表表号不存在");
+        }
+        if (list.size() > 1) {
+            throw new ServiceException(-900,"该水表表号出现重复");
+        }
+        deviceService.setValve(list.get(0));
+        log.info("end  valveControl");
+    }
+}

+ 4 - 4
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/WaterRelatedDeviceServiceImpl.java

@@ -57,8 +57,8 @@ public class WaterRelatedDeviceServiceImpl implements WaterRelatedDeviceService
         message.setSiteId(loginUser.getSiteId());
         message.setUserId(loginUser.getId());
         message.setMessageType(5);
-        message.setMessageTitle("光电直读表-设备列表-档案重置");
-        message.setMessageContent("光电直读表批量档案重置完成,成功"+inputDeviceDto.getDeviceIds().size()+"条,失败0条。");
+        message.setMessageTitle("远传水表-设备列表-档案重置");
+        message.setMessageContent("远传水表批量档案重置完成,成功"+inputDeviceDto.getDeviceIds().size()+"条,失败0条。");
         message.setRead(0);
         messageService.insertSelective(message);
         log.info("end fileReset");
@@ -94,8 +94,8 @@ public class WaterRelatedDeviceServiceImpl implements WaterRelatedDeviceService
         message.setSiteId(loginUser.getSiteId());
         message.setUserId(loginUser.getId());
         message.setMessageType(5);
-        message.setMessageTitle("光电直读表-设备列表-批量下发");
-        message.setMessageContent("光电直读表批量下发完成,成功"+success.get()+"条,失败"+fail.get()+"条。");
+        message.setMessageTitle("远传水表-设备列表-批量下发");
+        message.setMessageContent("远传水表批量下发完成,成功"+success.get()+"条,失败"+fail.get()+"条。");
         message.setRead(0);
         messageService.insertSelective(message);
         log.info("end batchReleaseFiles");

+ 8 - 8
smart-city-platform/src/main/java/com/bz/smart_city/service/importfile/AsyncTaskImportService.java

@@ -105,7 +105,7 @@ public class AsyncTaskImportService {
     @Async
     public void executeAsyncInstallTask(Import record){
         log.info("begin executeAsyncInstallTask!");
-        installResolverExcelTemplate.resolver(null,record,"新装水表管理-批量添加水表");
+        installResolverExcelTemplate.resolver(null,null,record,"新装水表管理-批量添加水表");
         log.info("begin executeAsyncInstallTask!");
     }
 
@@ -115,13 +115,13 @@ public class AsyncTaskImportService {
         WMeterType wMeterType = wMeterTypeMapper.getChannelIdAndLevel(sysId, 2);
         Channel channel = channelMapper.findById(sysId);
         if(StringUtils.equals("photoelectricMeter",channel.getChannelCode())){
-            gdDeviceResolverExcelTemplate.resolver(sysId,record,"设备列表-批量添加");
+            gdDeviceResolverExcelTemplate.resolver(sysId,null,record,"设备列表-批量添加");
         }else {
             //判断是否是水表场景
             if (wMeterType != null) {
-                waterDeviceResolverExcelTemplate.resolver(sysId,record,"设备列表-批量添加");
+                waterDeviceResolverExcelTemplate.resolver(sysId,null,record,"设备列表-批量添加");
             } else {
-                generalDeviceResolverExcelTemplate.resolver(sysId,record,"设备列表-批量添加");
+                generalDeviceResolverExcelTemplate.resolver(sysId,null,record,"设备列表-批量添加");
 
             }
         }
@@ -130,8 +130,8 @@ public class AsyncTaskImportService {
 
 
     @Async
-    public void executeAsyncBuildingTask(Import record, MultipartFile file){
-        buildingResolverExcelTemplate.resolver(null,record,"建筑列表-批量添加");
+    public void executeAsyncBuildingTask(Import record, Integer customerId, MultipartFile file){
+        buildingResolverExcelTemplate.resolver(null,customerId,record,"建筑列表-批量添加");
     }
 
     /**
@@ -562,11 +562,11 @@ public class AsyncTaskImportService {
 
     @Async
     public void executeAsyncConcentratorTask(Import record) {
-        concentratorResolveExcelTemplate.resolver(null,record,"集中器列表-批量添加");
+        concentratorResolveExcelTemplate.resolver(null,null,record,"集中器列表-批量添加");
     }
 
     @Async
     public void executeAsyncCollectorTask(Import record) {
-        collectorResolveExcelTemplate.resolver(null,record,"采集器列表-批量添加");
+        collectorResolveExcelTemplate.resolver(null,null,record,"采集器列表-批量添加");
     }
 }

+ 1 - 1
smart-city-platform/src/main/java/com/bz/smart_city/service/udip/UdipEtlDataCommandService.java

@@ -63,7 +63,7 @@ public class UdipEtlDataCommandService {
         }
     }
 
-    public JSONObject commandSendV2(String udipId, ValveCommandRequestDTO valveCommandRequest){
+    public JSONObject defaultCommandSend(String udipId, ValveCommandRequestDTO valveCommandRequest){
 
         Map<String,Object> map = new HashMap<>();
         map.put("meterCode",valveCommandRequest.getMeterCode());

+ 10 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/valve/DefaultValveControlProvider.java

@@ -0,0 +1,10 @@
+package com.bz.smart_city.service.valve;
+
+import com.bz.smart_city.dto.ValveCommandRequestDTO;
+
+public class DefaultValveControlProvider implements ValveControlProvider {
+    @Override
+    public void control(ValveCommandRequestDTO valveCommandRequest) {
+
+    }
+}

+ 7 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/valve/ValveControlProvider.java

@@ -0,0 +1,7 @@
+package com.bz.smart_city.service.valve;
+
+import com.bz.smart_city.dto.ValveCommandRequestDTO;
+
+public interface ValveControlProvider {
+    void control(ValveCommandRequestDTO valveCommandRequest);
+}

BIN
smart-city-platform/src/main/resources/excel/deviceTemplateV3.xlsx


+ 15 - 5
smart-city-platform/src/main/resources/mapper/BuildingMapper.xml

@@ -542,12 +542,16 @@
 <!--auto generated by codehelper on 2018-12-18-->
 	<select id="findBySiteId" resultMap="BaseResultMap">
         select
-        <include refid="Base_Column_List"/>
-        from sc_building
-        where status = 1
-        <if test="siteId != null"> and site_id=#{siteId} </if>
+        sb.id,sb.name,sb.province,sb.city,sb.region,sb.community
+        from sc_building sb
+        left join sc_community sc on(sc.id = sb.community)
+        where sb.status = 1
+        <if test="siteId != null"> and sb.site_id=#{siteId} </if>
         <if test="sysId != null">
-            and id in( SELECT sc_device.building_id FROM sc_device  WHERE sc_device.status = 1 <if test="siteId != null"> and sc_device.site_id=#{siteId} </if> and sc_device.sys_id = #{sysId}  GROUP BY sc_device.building_id)
+            and sb.id in( SELECT sc_device.building_id FROM sc_device  WHERE sc_device.status = 1 <if test="siteId != null"> and sc_device.site_id=#{siteId} </if> and sc_device.sys_id = #{sysId}  GROUP BY sc_device.building_id)
+        </if>
+        <if test="customerIds != null and customerIds.size() != 0">
+            and sc.customer_id in <foreach collection="customerIds" item="item" open="(" separator="," close=")">#{item}</foreach>
         </if>
     </select>
 
@@ -949,6 +953,9 @@
         where sb.status = 1
         <if test="siteId != null"> and sb.site_id =#{siteId} </if>
         <if test="buildingName != null and buildingName != ''"> AND sb.name LIKE concat('%',#{buildingName},'%')</if>
+        <if test="customerIds != null and customerIds.size() != 0">
+            and sc.customer_id in <foreach collection="customerIds" item="item" open="(" separator="," close=")">#{item}</foreach>
+        </if>
     </select>
 
     <select id="getBuildingByDeviceId" resultMap="BaseResultMap">
@@ -998,6 +1005,9 @@
     <select id="findByName" resultMap="BaseResultMap">
         select <include refid="Base_Column_List"></include> from sc_building where status = 1 and site_id = #{siteId}  and name = #{buildingName}
     </select>
+    <select id="findByNameV2" resultMap="BaseResultMap">
+        select <include refid="Base_Column_List"></include> from sc_building where status = 1 and site_id = #{siteId}  and name = #{buildingName} <if test="communityId != null"> and community = #{communityId}</if>
+    </select>
     <select id="findByIds" resultType="com.bz.smart_city.entity.Building">
         select <include refid="Base_Column_List"></include> from sc_building where status = 1
         and id in <foreach collection="ids" item="item" open="(" separator="," close=")">#{item}</foreach>

+ 6 - 0
smart-city-platform/src/main/resources/mapper/ConcentratorMapper.xml

@@ -294,6 +294,9 @@
     where scon.status = 1
     <if test="siteId != null"> and scon.site_id = #{siteId}</if>
     <if test="serialNumber != null and serialNumber != ''"> and scon.serial_number LIKE concat('%',#{serialNumber},'%')</if>
+    <if test="customerIds != null and customerIds.size() != 0">
+      and scon.customer_id in <foreach collection="customerIds" item="item" open="(" separator="," close=")">#{item}</foreach>
+    </if>
   </select>
 
   <select id="getAreaList" resultType="com.bz.smart_city.dto.BuildingSelectInfoDto">
@@ -344,6 +347,9 @@
     id,
     serial_number
     from sc_concentrator where status = 1 and site_id = #{siteId}
+    <if test="customerIds != null and customerIds.size() != 0">
+      and customer_id in <foreach collection="customerIds" item="item" open="(" separator="," close=")">#{item}</foreach>
+    </if>
   </select>
 
   <select id="findName" resultMap="BaseResultMap">

+ 2 - 7
smart-city-platform/src/main/resources/mapper/MeterReadRecordMapper.xml

@@ -1003,9 +1003,6 @@
         d.device_type as deviceType,
         d.building_id as buildingId,
         co.id as community,
-        p.id as province,
-        c.id as city,
-        r.id as region,
         cu.customer_name as customerName,
         b.`name`as buildingName,
         co.`name`as communityName,
@@ -1020,13 +1017,9 @@
         d.last_receive_time as lastReceiveTime
         FROM ${tableName} as t1
         LEFT JOIN sc_device d on(t1.device_id = d.id)
-        LEFT JOIN sc_w_meter_type wmt ON ( d.device_type = wmt.device_type_id AND wmt.`status` = 1 )
         LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
         LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
         LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
-        LEFT JOIN sc_area p ON ( b.province = p.id )
-        LEFT JOIN sc_area c ON ( b.city = c.id )
-        LEFT JOIN sc_area r ON ( b.region = r.id )
         LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
         LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
         LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
@@ -1040,6 +1033,8 @@
         <if test = "param.channelId != null and param.channelId != 0">
             and d.sys_id = #{param.channelId}
         </if>
+
+
         <if test="param.custormerId != null and param.custormerId != 0">
             and d.customer_id = #{param.custormerId}
         </if>

+ 2 - 2
smart-city-platform/src/main/resources/mapper/StatMeterReadRateByBuildingMapper.xml

@@ -315,7 +315,7 @@
         SUM(un_read_times) as un_read_times,
         ifnull(ROUND(sum(real_read_times)/sum(device_count)*100,2),0) as read_rate
         FROM ${tableName} ssmrrbb
-        WHERE ssmrrbb.stat_day = #{startDate}
+        WHERE ssmrrbb.stat_day = #{startDate} and ssmrrbb.channel_id != -99
         <if test="siteId != null"> and ssmrrbb.site_id = #{siteId} </if>
         <if test="buildingIds != null and buildingIds.size() != 0"> and ssmrrbb.building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
         <if test="customerIds != null and customerIds.size() != 0"> and ssmrrbb.customer_id in <foreach collection="customerIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
@@ -407,7 +407,7 @@
         FROM ${tableName} ssmrrbb
         left join sc_channel sc on(sc.id = ssmrrbb.channel_id)
         WHERE
-        ssmrrbb.stat_day =  #{startDate}
+        ssmrrbb.stat_day =  #{startDate} and ssmrrbb.channel_id != -99
         <if test="siteId != null"> and ssmrrbb.site_id = #{siteId} </if>
         <if test="buildingIds != null and buildingIds.size() != 0"> and ssmrrbb.building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
         <if test="customerIds != null and customerIds.size() != 0"> and ssmrrbb.customer_id in <foreach collection="customerIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>

+ 113 - 0
smart-city-platform/src/main/resources/mapper/ThirdPartyAppMapper.xml

@@ -0,0 +1,113 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.bz.smart_city.dao.ThirdPartyAppMapper">
+  <resultMap id="BaseResultMap" type="com.bz.smart_city.entity.ThirdPartyApp">
+    <!--@mbg.generated-->
+    <!--@Table sc_third_party_app-->
+    <id column="id" property="id" />
+    <result column="name" property="name" />
+    <result column="app_id" property="appId" />
+    <result column="app_secret_key" property="appSecretKey" />
+    <result column="status" property="status" />
+    <result column="create_by" property="createBy" />
+    <result column="create_date" property="createDate" />
+    <result column="update_by" property="updateBy" />
+    <result column="update_date" property="updateDate" />
+  </resultMap>
+  <sql id="Base_Column_List">
+    <!--@mbg.generated-->
+    id, `name`, app_id, app_secret_key, `status`, create_by, create_date, update_by, 
+    update_date
+  </sql>
+  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.bz.smart_city.entity.ThirdPartyApp" useGeneratedKeys="true">
+    <!--@mbg.generated-->
+    insert into sc_third_party_app
+    <trim prefix="(" suffix=")" suffixOverrides=",">
+      <if test="name != null">
+        `name`,
+      </if>
+      <if test="appId != null">
+        app_id,
+      </if>
+      <if test="appSecretKey != null">
+        app_secret_key,
+      </if>
+      <if test="status != null">
+        `status`,
+      </if>
+      <if test="createBy != null">
+        create_by,
+      </if>
+      <if test="createDate != null">
+        create_date,
+      </if>
+      <if test="updateBy != null">
+        update_by,
+      </if>
+      <if test="updateDate != null">
+        update_date,
+      </if>
+    </trim>
+    <trim prefix="values (" suffix=")" suffixOverrides=",">
+      <if test="name != null">
+        #{name},
+      </if>
+      <if test="appId != null">
+        #{appId},
+      </if>
+      <if test="appSecretKey != null">
+        #{appSecretKey},
+      </if>
+      <if test="status != null">
+        #{status},
+      </if>
+      <if test="createBy != null">
+        #{createBy},
+      </if>
+      <if test="createDate != null">
+        #{createDate},
+      </if>
+      <if test="updateBy != null">
+        #{updateBy},
+      </if>
+      <if test="updateDate != null">
+        #{updateDate},
+      </if>
+    </trim>
+  </insert>
+  <update id="updateByPrimaryKeySelective" parameterType="com.bz.smart_city.entity.ThirdPartyApp">
+    <!--@mbg.generated-->
+    update sc_third_party_app
+    <set>
+      <if test="name != null">
+        `name` = #{name},
+      </if>
+      <if test="appId != null">
+        app_id = #{appId},
+      </if>
+      <if test="appSecretKey != null">
+        app_secret_key = #{appSecretKey},
+      </if>
+      <if test="status != null">
+        `status` = #{status},
+      </if>
+      <if test="createBy != null">
+        create_by = #{createBy},
+      </if>
+      <if test="createDate != null">
+        create_date = #{createDate},
+      </if>
+      <if test="updateBy != null">
+        update_by = #{updateBy},
+      </if>
+      <if test="updateDate != null">
+        update_date = #{updateDate},
+      </if>
+    </set>
+    where id = #{id}
+  </update>
+
+  <select id="findByAppId" resultMap="BaseResultMap">
+    select id,app_id,app_secret_key from sc_third_party_app where status = 1 and app_id = #{appId}
+  </select>
+</mapper>