Browse Source

未提交文件提交
增加换表接口

wangli 4 years ago
parent
commit
f0d03d2201
18 changed files with 997 additions and 8 deletions
  1. 101 0
      smart-city-platform/src/main/java/com/bz/smart_city/commom/security/mobile/MobileLoginAuthenticationFilter.java
  2. 65 0
      smart-city-platform/src/main/java/com/bz/smart_city/commom/security/mobile/MobileLoginAuthenticationProvider.java
  3. 62 0
      smart-city-platform/src/main/java/com/bz/smart_city/commom/security/mobile/MobileLoginAuthenticationToken.java
  4. 175 0
      smart-city-platform/src/main/java/com/bz/smart_city/commom/security/mobile/MobileLoginUserDetailService.java
  5. 48 0
      smart-city-platform/src/main/java/com/bz/smart_city/commom/security/mobile/MobileSecurityConfig.java
  6. 13 4
      smart-city-platform/src/main/java/com/bz/smart_city/controller/pay/AmountWaterUsedAmountController.java
  7. 1 0
      smart-city-platform/src/main/java/com/bz/smart_city/dao/CustomerMapper.java
  8. 5 0
      smart-city-platform/src/main/java/com/bz/smart_city/dao/pay/AmountWaterUsedAmountMapper.java
  9. 36 0
      smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/DeviceReplaceRecordDto.java
  10. 47 0
      smart-city-platform/src/main/java/com/bz/smart_city/entity/pay/DeviceReplaceRecord.java
  11. 9 0
      smart-city-platform/src/main/java/com/bz/smart_city/quartz/service/AmountSynService.java
  12. 229 0
      smart-city-platform/src/main/java/com/bz/smart_city/quartz/service/impl/AmountSynServiceImpl.java
  13. 51 0
      smart-city-platform/src/main/java/com/bz/smart_city/service/SmsService.java
  14. 55 4
      smart-city-platform/src/main/java/com/bz/smart_city/service/impl/pay/AmountWaterUsedAmountServiceImpl.java
  15. 7 0
      smart-city-platform/src/main/java/com/bz/smart_city/service/pay/AmountWaterUsedAmountService.java
  16. 43 0
      smart-city-platform/src/main/resources/mapper/AreaMapper.xml
  17. 5 0
      smart-city-platform/src/main/resources/mapper/CustomerMapper.xml
  18. 45 0
      smart-city-platform/src/main/resources/mapper/pay/AmountWaterUsedAmountMapper.xml

+ 101 - 0
smart-city-platform/src/main/java/com/bz/smart_city/commom/security/mobile/MobileLoginAuthenticationFilter.java

@@ -0,0 +1,101 @@
+package com.bz.smart_city.commom.security.mobile;
+
+import org.springframework.security.authentication.AuthenticationServiceException;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+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;
+
+public class MobileLoginAuthenticationFilter extends AbstractAuthenticationProcessingFilter {
+    // ~ Static fields/initializers
+    // =====================================================================================
+
+    public static final String SPRING_SECURITY_FORM_MOBILE_KEY = "mobile";
+    public static final String SPRING_SECURITY_FORM_PASSWORD_KEY = "password";
+
+    private String mobileParameter = SPRING_SECURITY_FORM_MOBILE_KEY;
+    private String passwordParameter = SPRING_SECURITY_FORM_PASSWORD_KEY;
+    private boolean postOnly = true;
+
+    // ~ Constructors
+    // ===================================================================================================
+
+    public MobileLoginAuthenticationFilter() {
+        super(new AntPathRequestMatcher("/user/mobileLogin", "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 mobile = obtainMobile(request);
+        String password = obtainPassword(request);
+
+        if (mobile == null) {
+            mobile = "";
+        }
+
+        if (password == null) {
+            password = "";
+        }
+
+        mobile = mobile.trim();
+
+        MobileLoginAuthenticationToken authRequest = new MobileLoginAuthenticationToken(mobile, password);
+
+        // Allow subclasses to set the "details" property
+        setDetails(request, authRequest);
+
+        return this.getAuthenticationManager().authenticate(authRequest);
+    }
+
+    private String obtainMobile(HttpServletRequest request) {
+        return request.getParameter(mobileParameter);
+    }
+
+
+    protected String obtainPassword(HttpServletRequest request) {
+        return request.getParameter(passwordParameter);
+    }
+
+
+    protected void setDetails(HttpServletRequest request, MobileLoginAuthenticationToken authRequest) {
+        authRequest.setDetails(authenticationDetailsSource.buildDetails(request));
+    }
+
+
+    public void setMobileParameter(String mobileParameter) {
+        Assert.hasText(mobileParameter, "Username parameter must not be empty or null");
+        this.mobileParameter = mobileParameter;
+    }
+
+
+    public void setPasswordParameter(String passwordParameter) {
+        Assert.hasText(passwordParameter, "Password parameter must not be empty or null");
+        this.passwordParameter = passwordParameter;
+    }
+
+    public void setPostOnly(boolean postOnly) {
+        this.postOnly = postOnly;
+    }
+
+    public final String getmobileParameter() {
+        return mobileParameter;
+    }
+
+    public final String getPasswordParameter() {
+        return passwordParameter;
+    }
+}

+ 65 - 0
smart-city-platform/src/main/java/com/bz/smart_city/commom/security/mobile/MobileLoginAuthenticationProvider.java

@@ -0,0 +1,65 @@
+package com.bz.smart_city.commom.security.mobile;
+
+import lombok.extern.slf4j.Slf4j;
+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.factory.PasswordEncoderFactories;
+import org.springframework.security.crypto.password.PasswordEncoder;
+import org.springframework.util.Assert;
+
+@Slf4j
+public class MobileLoginAuthenticationProvider implements AuthenticationProvider {
+
+    private UserDetailsService userDetailsService;
+
+    private PasswordEncoder passwordEncoder;
+
+    @Override
+    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
+        MobileLoginAuthenticationToken authenticationToken = (MobileLoginAuthenticationToken)authentication;
+        UserDetails userDetails = userDetailsService.loadUserByUsername((String) authenticationToken.getPrincipal());
+        if (userDetails == null) {
+            throw new InternalAuthenticationServiceException("无法获取用户信息");
+        }
+        String presentedPassword = authenticationToken.getCredentials().toString();
+
+
+        if (!passwordEncoder.matches(presentedPassword, userDetails.getPassword())) {
+            log.debug("Authentication failed: password does not match stored value");
+
+            throw new BadCredentialsException("密码错误");
+        }
+        MobileLoginAuthenticationToken authenticationTokenReslut = new MobileLoginAuthenticationToken(userDetails,authenticationToken.getCredentials(),userDetails.getAuthorities());
+
+        authenticationTokenReslut.setDetails(authenticationToken.getDetails());
+
+        return authenticationTokenReslut;
+    }
+
+    @Override
+    public boolean supports(Class<?> authentication) {
+        return MobileLoginAuthenticationToken.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;
+    }
+}

+ 62 - 0
smart-city-platform/src/main/java/com/bz/smart_city/commom/security/mobile/MobileLoginAuthenticationToken.java

@@ -0,0 +1,62 @@
+package com.bz.smart_city.commom.security.mobile;
+
+import org.springframework.security.authentication.AbstractAuthenticationToken;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.SpringSecurityCoreVersion;
+
+import java.util.Collection;
+
+/**
+ * 自定义手机号码和密码登录
+ */
+public class MobileLoginAuthenticationToken extends AbstractAuthenticationToken {
+    private static final long serialVersionUID = SpringSecurityCoreVersion.SERIAL_VERSION_UID;
+
+    /**
+     * 手机号
+     */
+    private final Object principal;
+    private Object credentials;
+
+
+    public MobileLoginAuthenticationToken(String mobile, Object credentials) {
+        super(null);
+        this.principal = mobile;
+        this.credentials = credentials;
+        setAuthenticated(false);
+    }
+
+    public MobileLoginAuthenticationToken(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();
+    }
+
+}

+ 175 - 0
smart-city-platform/src/main/java/com/bz/smart_city/commom/security/mobile/MobileLoginUserDetailService.java

@@ -0,0 +1,175 @@
+package com.bz.smart_city.commom.security.mobile;
+
+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 MobileLoginUserDetailService implements UserDetailsService {
+    @Resource
+    private UserMapper userMapper;
+    @Resource
+    private PermissionService permissionService;
+    @Resource
+    private SiteUserMapper siteUserMapper;
+    @Resource
+    private SiteMapper siteMapper;
+    @Resource
+    private ProgramMapper programMapper;
+    @Resource
+    private ProgramItemMapper programItemMapper;
+    @Resource
+    private CustomerMapper customerMapper;
+    @Autowired
+    private RedisUtil redisUtil;
+
+    @Override
+    public UserDetails loadUserByUsername(String mobile) throws UsernameNotFoundException {
+        User user = userMapper.findUserByMobile(mobile);
+        if (user == null) {
+            throw new UsernameNotFoundException("该用户不存在");
+        }
+
+        //判断是否禁用
+        if (user.getStatus() == 2) {
+            throw new DisabledException("账号已被禁用");
+        }
+        LoginUser loginUser = new LoginUser();
+        BeanUtils.copyProperties(user, loginUser);
+
+        Map<Integer, List<Permission>> permissionMap = new HashMap<>();
+        Map<Integer, List<ProgramItem>> datePermissionMap = new HashMap<>();
+        if (user.getIsSuperAdmin() == 1) {
+            //超级管理员的权限
+            List<Permission> permissions = permissionService.getPermissionBySuperAdmin();
+            permissionMap.put(0, permissions);
+            loginUser.setCurrentSiteId(0);
+            loginUser.setType(1);
+        } else  {
+            //站点管理员(多站点)
+            Integer siteId = null;
+            List<Site> siteList = siteUserMapper.getSiteByUserId(user.getId());
+            List<SiteUserDto> siteV2List = siteUserMapper.getSiteByUserIdV2(user.getId());
+            if (siteList == null || siteList.size() == 0) {
+                throw new ValidateCodeException("该用户未关联站点");
+            }
+
+            siteV2List.forEach(site -> {
+                if(site.getUserType() == 2){
+                    List<Permission> permissions = permissionService.getPermissionBySiteAdminV2(site.getId(),site.getType());;
+                    permissionMap.put(site.getId(), permissions);
+                }else {
+                    permissionMap.put(site.getId(), permissionService.getPermissionByUserId(user.getId(), site.getId()));
+                }
+
+
+                List<ProgramItem> programItemList = programItemMapper.getBySiteIdAndUserId(site.getId(), user.getId());
+                if (programItemList != null && programItemList.size() > 0) {
+                    datePermissionMap.put(site.getId(), programItemList);
+                }
+            });
+            permissionMap.put(0, newArrayList());
+
+
+            String key = "useSelectSiteId:" + user.getId();
+            byte[] useSelectSiteIdByte = redisUtil.get(key.getBytes());
+            if (useSelectSiteIdByte != null) {
+                Integer useSelectSiteId = (Integer) ByteArrayUtils.bytesToObject(useSelectSiteIdByte).get();
+                if (!checkSite(siteList, useSelectSiteId)) {
+                    siteId = siteList.size()>0?siteList.get(0).getId():0;
+                    //保存redis
+                    redisUtil.setExpire(key.getBytes(), ByteArrayUtils.objectToBytes(siteId).get());
+                }else {
+                    siteId = useSelectSiteId;
+                }
+            }else {
+                siteId = siteList.size()>0?siteList.get(0).getId():0;
+                //保存redis
+                redisUtil.setExpire(key.getBytes(), ByteArrayUtils.objectToBytes(siteId).get());
+            }
+
+
+            SiteUser siteUser = siteUserMapper.findBySiteIdAndUserId(siteId,user.getId());
+
+            loginUser.setType(siteUser.getType());
+            loginUser.setOrgId(siteUser.getOrganId());
+            loginUser.setSiteId(siteId);
+            loginUser.setCurrentSiteId(siteId);
+            loginUser.setSiteList(siteList);
+            loginUser.setIsSiteAdmin(siteUser.getIsAdmin());//站点管理员
+            loginUser.setSiteType(checkSiteType(siteList,siteId));
+
+            Site site = siteMapper.findById(siteId);
+            loginUser.setCustomerId(site.getCustomerId());
+            loginUser.setCustomerName(site.getCustomerName());
+            loginUser.setOrgId(siteUser.getOrganId());
+
+            //查询数据权限
+
+        }
+
+        /*else {
+            //查询平台用户的站点
+            Site site = siteUserMapper.findSiteByUserId(user.getId());
+            if (site != null) {
+                List<Site> siteList = newArrayList();
+                siteList.add(site);
+                loginUser.setSiteId(site.getId());
+                loginUser.setCurrentSiteId(site.getId());
+                loginUser.setSiteList(siteList);
+
+                //查询功能权限
+                permissionMap.put(site.getId(), permissionService.getPermissionByUserId(user.getId(), null));
+                //查询数据权限
+                datePermissionMap.put(site.getId(), programItemMapper.getBySiteIdAndUserId(site.getId(), user.getId()));
+            }
+        }*/
+
+
+        /*Customer customer = null;
+        if(loginUser.getOrgId()!=null) {
+            customer = customerMapper.findByOrgId(loginUser.getOrgId());
+            //loginUser.setOrgId(user.getOrganId());
+        }
+        if(customer!=null)
+          loginUser.setCustomerId(customer.getId());*/
+        loginUser.setPermissionMap(permissionMap);
+        loginUser.setDataPermissionMap(datePermissionMap);
+        return loginUser;
+    }
+
+    //判断siteList中是否包含siteId
+    private boolean checkSite(List<Site> siteList, Integer siteId) {
+        return siteList.parallelStream().anyMatch(site -> site.getId().equals(siteId));
+    }
+
+    private Integer checkSiteType(List<Site> siteList, Integer siteId) {
+        Integer siteType = null;
+        for (Site site : siteList) {
+            if(site.getId().equals(siteId)){
+                siteType =  site.getType();
+                break;
+            }
+        }
+        return siteType;
+    }
+}

+ 48 - 0
smart-city-platform/src/main/java/com/bz/smart_city/commom/security/mobile/MobileSecurityConfig.java

@@ -0,0 +1,48 @@
+package com.bz.smart_city.commom.security.mobile;
+
+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.authentication.builders.AuthenticationManagerBuilder;
+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.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 MobileSecurityConfig extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> {
+    @Autowired
+    @Qualifier("userAuthenticationSuccessHandler")
+    private AuthenticationSuccessHandler authenticationSuccessHandler;
+    @Autowired
+    @Qualifier("userAuthenticationFailureHandler")
+    private AuthenticationFailureHandler authenticationFailureHandler;
+    @Autowired
+    private MobileLoginUserDetailService userDetailsService;
+    @Bean
+    public PasswordEncoder passwordEncoder() {
+        return new BCryptPasswordEncoder();
+    }
+
+
+
+    @Override
+    public void configure(HttpSecurity http) throws Exception {
+        MobileLoginAuthenticationFilter mobileLoginAuthenticationFilter = new MobileLoginAuthenticationFilter();
+        mobileLoginAuthenticationFilter.setAuthenticationManager(http.getSharedObject(AuthenticationManager.class));
+        mobileLoginAuthenticationFilter.setAuthenticationSuccessHandler(authenticationSuccessHandler);
+        mobileLoginAuthenticationFilter.setAuthenticationFailureHandler(authenticationFailureHandler);
+
+        MobileLoginAuthenticationProvider mobileAuthenticationProvider = new MobileLoginAuthenticationProvider();
+        mobileAuthenticationProvider.setUserDetailsService(userDetailsService);
+        mobileAuthenticationProvider.setPasswordEncoder(passwordEncoder());
+        http.authenticationProvider(mobileAuthenticationProvider)
+                .addFilterAfter(mobileLoginAuthenticationFilter, UsernamePasswordAuthenticationFilter.class);
+    }
+}

+ 13 - 4
smart-city-platform/src/main/java/com/bz/smart_city/controller/pay/AmountWaterUsedAmountController.java

@@ -3,17 +3,14 @@ package com.bz.smart_city.controller.pay;
 import com.bz.smart_city.commom.model.AjaxMessage;
 import com.bz.smart_city.commom.model.Pagination;
 import com.bz.smart_city.commom.model.ResultStatus;
-import com.bz.smart_city.dao.pay.BaseClosingAccountInfoMapper;
 import com.bz.smart_city.dto.pay.AmountWaterUsedAmountDto;
-import com.bz.smart_city.dto.pay.BaseClosingAccountDataDto;
 import com.bz.smart_city.dto.pay.BaseClosingAccountInfoDto;
-import com.bz.smart_city.entity.pay.AmountWaterUsedAmount;
+import com.bz.smart_city.dto.pay.DeviceReplaceRecordDto;
 import com.bz.smart_city.service.pay.AmountWaterUsedAmountService;
 import com.bz.smart_city.service.pay.BaseClosingAccountInfoService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
-import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.*;
@@ -125,5 +122,17 @@ public class AmountWaterUsedAmountController {
         return ajaxMessage;
     }
 
+    //换表接口
+
+    @ResponseBody
+    @GetMapping("/synDeviceReplaceRecord")
+    @ApiOperation(value = "获取全部审核条数")
+    public AjaxMessage synDeviceReplaceRecord(
+            @ApiParam(value = "h换表记录")@RequestBody(required = true) DeviceReplaceRecordDto deviceReplaceRecordDto
+     ){
+        amountWaterUsedAmountService.saveDeviceReplaceRecord(deviceReplaceRecordDto);
+
+        return new AjaxMessage<>(ResultStatus.OK);
+    }
 
 }

+ 1 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dao/CustomerMapper.java

@@ -36,4 +36,5 @@ public interface CustomerMapper {
 
     Integer countChildrenNum(@Param("customerId") Integer customerId);
 
+    CustomerDto getCustomerByCustomerno(@Param("customerNo") String customerNo);
 }

+ 5 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dao/pay/AmountWaterUsedAmountMapper.java

@@ -7,6 +7,7 @@ import com.bz.smart_city.dto.pay.ReplaceMeterDto;
 import com.bz.smart_city.entity.ProgramItem;
 import com.bz.smart_city.entity.pay.AmountWaterUsedAmount;
 import com.bz.smart_city.entity.pay.AmountWaterUsedAmountByDay;
+import com.bz.smart_city.entity.pay.DeviceReplaceRecord;
 import com.bz.smart_city.entity.pay.archives.PayBaseCustomerandmeterrela;
 import org.apache.ibatis.annotations.MapKey;
 import org.apache.ibatis.annotations.Mapper;
@@ -74,4 +75,8 @@ public interface AmountWaterUsedAmountMapper {
     @MapKey("deviceId")
     HashMap<BigInteger, ReplaceMeterCountDto> getRepalceRecordCount(@Param("stTime")LocalDateTime stTime, @Param("etTime")LocalDateTime etTime, @Param("list")List<BigInteger> list,@Param("siteId")Integer siteId,@Param("customerId")Integer customerId);
 
+    AmountWaterUsedAmount getLastReadrecord(@Param("metercode") String metercode, @Param("siteId") Integer siteId,@Param("customerId")Integer customerId);
+
+    void insertReplaceRecord( @Param("deviceReplaceRecord") DeviceReplaceRecord deviceReplaceRecord);
+
 }

+ 36 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/DeviceReplaceRecordDto.java

@@ -0,0 +1,36 @@
+package com.bz.smart_city.dto.pay;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+/**
+ * @description
+ * @auto wangli
+ * @data 2020-09-25 16:18
+ */
+@ApiModel("换表信息")
+@Data
+public class DeviceReplaceRecordDto implements Serializable {
+
+    private static final long serialVersionUID = 1669365207968152952L;
+
+    @ApiModelProperty("水表编码")
+    private String metercode;
+    @ApiModelProperty("旧表电子号")
+    private String oldEleno;
+    @ApiModelProperty("新表电子号")
+    private String newEleno;
+    @ApiModelProperty(value = "旧表起度")
+    private BigDecimal oldStarReading;
+    @ApiModelProperty(value = "旧表止度")
+    private BigDecimal oldReading;
+    @ApiModelProperty("新表起度")
+    private BigDecimal newStartcount;
+    @ApiModelProperty("客户编号")
+    private String customerNo;
+
+}

+ 47 - 0
smart-city-platform/src/main/java/com/bz/smart_city/entity/pay/DeviceReplaceRecord.java

@@ -0,0 +1,47 @@
+package com.bz.smart_city.entity.pay;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.time.LocalDateTime;
+
+/**
+ * @description 换表记录
+ * @auto wangli
+ * @data 2020-09-25 15:30
+ */
+@Data
+public class DeviceReplaceRecord implements Serializable {
+
+    @ApiModelProperty("主键id")
+    private BigInteger id;
+    @ApiModelProperty("水表编码")
+    private String metercode;
+    @ApiModelProperty("旧表电子号")
+    private String oldEleno;
+    @ApiModelProperty("新表电子号")
+    private String newEleno;
+    @ApiModelProperty("旧表上期止度")
+    private BigDecimal oldLastreading;
+    @ApiModelProperty("旧表本次止度")
+    private BigDecimal oldReading;
+    @ApiModelProperty("旧表水量")
+    private BigDecimal oldAmount;
+    @ApiModelProperty("新表起度")
+    private BigDecimal newStartcount;
+    @ApiModelProperty("创建时间")
+    private LocalDateTime createDate;
+    @ApiModelProperty("备注")
+    private String remarks;
+    @ApiModelProperty("站点id")
+    private Integer siteId ;
+    @ApiModelProperty("客户id")
+    private Integer customerId;
+    @ApiModelProperty("账期年")
+    private Integer year;
+    @ApiModelProperty("账期月")
+    private Integer month;
+}

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

@@ -0,0 +1,9 @@
+package com.bz.smart_city.quartz.service;
+
+import com.bz.smart_city.dto.pay.PayBaseConfigDto;
+
+public interface AmountSynService {
+
+    void saveQrtzTask(PayBaseConfigDto payBaseConfigDto);
+    void amountUpdate(Integer siteId, Integer customerId);
+}

+ 229 - 0
smart-city-platform/src/main/java/com/bz/smart_city/quartz/service/impl/AmountSynServiceImpl.java

@@ -0,0 +1,229 @@
+package com.bz.smart_city.quartz.service.impl;
+
+import com.bz.smart_city.commom.util.DateTimeUtil;
+import com.bz.smart_city.dao.pay.AmountWaterUsedAmountMapper;
+import com.bz.smart_city.dao.pay.BaseClosingAccountInfoMapper;
+import com.bz.smart_city.dao.pay.PayBaseConfigMapper;
+import com.bz.smart_city.dto.pay.*;
+import com.bz.smart_city.quartz.service.AmountSynService;
+import com.bz.smart_city.quartz.service.JobAndTriggerService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.time.Duration;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * @description
+ * @auto wangli
+ * @data 2020-09-27 10:51
+ */
+@Slf4j
+@Component
+public class AmountSynServiceImpl implements AmountSynService {
+
+    @Value("1")
+    private BigInteger createBy;
+
+    @Resource
+    private BaseClosingAccountInfoMapper baseClosingAccountInfoMapper;
+    @Resource
+    private AmountWaterUsedAmountMapper amountWaterUsedAmountMapper;
+    @Resource
+    private PayBaseConfigMapper payBaseConfigMapper;
+    @Resource
+    private JobAndTriggerService jobAndTriggerService;
+    @Override
+    public void saveQrtzTask(PayBaseConfigDto payBaseConfigDto) {
+
+    }
+
+    @Override
+    public void amountUpdate(Integer siteId, Integer customerId) {
+
+
+        //获取水表信息
+        //调取接口获取水量信息
+        //保存水量信息
+    }
+
+ /*   public void amountUpdate(Integer siteId, Integer customerId){
+
+        //获取最新账期
+
+        List<BaseClosingAccountInfoDto> baseClosingAccountInfoDtos = baseClosingAccountInfoMapper.getList(null,null, BigInteger.valueOf(siteId),BigInteger.valueOf(customerId),0);
+        if(baseClosingAccountInfoDtos.size()>0){
+            //customerId  accountPeriod 是否有结算计划
+            BaseClosingAccountInfoDto baseClosingAccountInfoDto =  baseClosingAccountInfoDtos.get(0);
+            Integer year = baseClosingAccountInfoDto.getYear();
+            Integer month = baseClosingAccountInfoDto.getMonth();
+
+            String accountPeriod = year + String.format("%02d",month);
+
+
+            ClearingRecord clearingRecord  = //clearingRecordMapper.findClearingRecordByAccoutPeriodAndCust(accountPeriod,Integer.valueOf(customerId));
+            if(clearingRecord!=null){
+                //产生水量基础计划
+                Integer totalNum = amountWaterUsedAmountMapper.getAllAmountCount(year,month,siteId,customerId);
+                Integer num = totalNum / 500 + (totalNum % 500 > 0 ? 1 : 0);
+                log.info("抄表计划生成开始:" + LocalDateTime.now() + ",计划条数" + totalNum);
+                for (int i = 0; i < num; i++)
+                {
+                    int a = amountWaterUsedAmountMapper.createdAmount(year,month,siteId,customerId);
+                    log.info("成功条数" + i + ":" + a);
+                }
+                log.info("抄表计划生成完成:" + LocalDateTime.now());
+
+                //获取结算水量
+                log.info("水量同步开始:" + LocalDateTime.now());
+                HashMap<BigInteger, ClearingDataInfoDto> clearingDataHashMap = clearingRecordItemMapper.findClearingDataHashMap(clearingRecord.getId(),1);
+                if(clearingDataHashMap!=null&&clearingDataHashMap.size()>0) {
+                    //同步水量
+                    List<AmountWaterUsedAmountDto> amountWaterUsedAmountDtos = amountWaterUsedAmountMapper.getAllAmountRecord(year, month,siteId, customerId);
+                    //批量更新水量信息
+                    List<AmountWaterUsedAmountDto> updates = new ArrayList<>();
+
+                    //换表记录
+                    HashMap<BigInteger, ReplaceMeterCountDto> replaceMap = new HashMap<>();
+                    if(amountWaterUsedAmountDtos.size() > 0){
+                        LocalDateTime stTime = LocalDateTime.ofInstant(baseClosingAccountInfoDtos.get(0).getStartTime().toInstant(), ZoneId.systemDefault());
+                        HashMap<BigInteger, ReplaceMeterCountDto> childReplaceMap = amountWaterUsedAmountMapper.getRepalceRecordCount(stTime,null,null,null,customerId);
+                        if(childReplaceMap.size() >0){
+                            List<ReplaceMeterDto> replaceMeterDtoList = amountWaterUsedAmountMapper.getRepalceRecordDetail(stTime,null,null,null,customerId);
+                            if(replaceMeterDtoList.size() >0){
+                                for(int i=0;i<replaceMeterDtoList.size();i++){
+                                    if(childReplaceMap.containsKey(replaceMeterDtoList.get(i).getDeviceId())){
+                                        ReplaceMeterCountDto replaceMeterCountDto = childReplaceMap.get(replaceMeterDtoList.get(i).getDeviceId());
+                                        if(replaceMeterCountDto.getReplaceMeterDtoList() == null)
+                                        {
+                                            replaceMeterCountDto.setReplaceMeterDtoList(new ArrayList<>());
+                                        }
+                                        replaceMeterCountDto.getReplaceMeterDtoList().add(replaceMeterDtoList.get(i));
+                                    }
+                                }
+                            }
+                            replaceMap.putAll(childReplaceMap);
+                        }
+                    }
+
+                    for (AmountWaterUsedAmountDto amountWaterUsedAmountDto : amountWaterUsedAmountDtos) {
+                        BigInteger watermeterId = amountWaterUsedAmountDto.getWatermeterId();
+                        if (watermeterId != null && clearingDataHashMap.containsKey(watermeterId)) {
+                            ClearingDataInfoDto clearingDataDTO = clearingDataHashMap.get(watermeterId);
+                            BigInteger amountId = amountWaterUsedAmountDto.getId();//水量id
+                            BigDecimal readingOld = amountWaterUsedAmountDto.getLastreading();//上期止度
+                            if (clearingDataDTO.getCurrentPeriodData() != null) {
+                                BigDecimal readingNew = new BigDecimal(clearingDataDTO.getCurrentPeriodData()).setScale(0, BigDecimal.ROUND_DOWN);//本期止度
+                                BigInteger meterid = amountWaterUsedAmountDto.getWatermeterId();//水表id
+                                BigDecimal payAmount = BigDecimal.ZERO;//结算水量
+                                Date lastAmountDate = amountWaterUsedAmountDto.getLastrecorddate();
+                                BigDecimal Amount = BigDecimal.ZERO;//实际用水量
+                                BigDecimal tempReading = BigDecimal.ZERO;
+                                tempReading = readingOld;//起度或上期的止度
+                                String readDate = clearingDataDTO.getMeterReadDate();
+                                Integer calculateway = amountWaterUsedAmountDto.getCalculateway();
+
+                                //换表记录计算
+                                boolean replace = false;
+                                ReplaceMeterCountDto replaceMeterCountDto=null;
+                                if(replaceMap.containsKey(watermeterId)){
+                                    replaceMeterCountDto = replaceMap.get(watermeterId);
+                                    //有换表记录且换表时间在两次同步之间 用水量=(换表中的旧表止度-上次抄表止度) + (本次止度-换表中的新表起度)
+                                    if(replaceMeterCountDto != null){
+                                        LocalDateTime currTime = LocalDateTime.parse(readDate, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S"));//本次抄表时间
+                                        LocalDateTime previousTime = LocalDateTime.ofInstant(amountWaterUsedAmountDto.getLastrecorddate().toInstant(),ZoneId.systemDefault()); //上个帐期的结算抄表时间
+
+                                        ReplaceMeterDto oldReplaceMeterDto = null;
+                                        for(int i = 0;i<replaceMeterCountDto.getReplaceMeterDtoList().size();i++){
+                                            LocalDateTime replaceTime = replaceMeterCountDto.getReplaceMeterDtoList().get(i).getReplaceTime();   //换表时间
+
+                                            Duration duration1 = Duration.between(previousTime,replaceTime);
+                                            Duration duration2 = Duration.between(replaceTime,currTime);
+                                            if(duration1.toMillis() > 0  && duration2.toMinutes() > 0){
+                                                BigDecimal replaceEndData = new BigDecimal(replaceMeterCountDto.getReplaceMeterDtoList().get(i).getOldEnd()).setScale(2,BigDecimal.ROUND_DOWN);//换表中的旧表止度
+                                                BigDecimal replaceData = BigDecimal.ZERO;
+                                                if(oldReplaceMeterDto == null)
+                                                    replaceData = tempReading;
+                                                else
+                                                    replaceData = new BigDecimal(oldReplaceMeterDto.getNewBegin()).setScale(0,BigDecimal.ROUND_DOWN);//换表中的起度
+                                                BigDecimal oldMeterUse = replaceEndData.subtract(replaceData); //旧表用量
+
+                                                Amount = Amount.add(oldMeterUse);
+                                                replace = true;
+
+                                                oldReplaceMeterDto = replaceMeterCountDto.getReplaceMeterDtoList().get(i);
+                                            }
+                                            else {
+                                                break;
+                                            }
+
+                                        }
+
+                                        //新表用量
+                                        if(oldReplaceMeterDto != null){
+                                            BigDecimal replaceNewDate = new BigDecimal(oldReplaceMeterDto.getNewBegin()).setScale(0,BigDecimal.ROUND_DOWN);//换表中的新表起度
+                                            BigDecimal newMeterUse = readingNew.subtract(replaceNewDate);//新表用量
+                                            Amount = Amount.add(newMeterUse);
+                                        }
+
+                                    }
+                                }
+
+                                if(!replace){
+                                    if (readingNew.compareTo(tempReading) > 0)
+                                        Amount = Amount.add(readingNew.subtract(tempReading));
+                                }
+
+
+                                //计量方式判断
+
+                                if (calculateway.equals(1))//按实际用量
+                                    payAmount = Amount;
+                                else if (calculateway.equals(2))//按固定量
+                                    payAmount = BigDecimal.valueOf(amountWaterUsedAmountDto.getFixedamount());
+                                else
+                                    payAmount = Amount;
+
+                                if (payAmount.compareTo(BigDecimal.ZERO) < 0) {
+                                    continue;
+                                }
+
+                                amountWaterUsedAmountDto.setReading(readingNew);
+                                amountWaterUsedAmountDto.setRecorddate(DateTimeUtil.parseDate(readDate, DateTimeUtil.DATE_TIME_FORMAT_SECOND));
+                                amountWaterUsedAmountDto.setAmount(Amount);
+                                amountWaterUsedAmountDto.setPayamount(payAmount);
+
+                                updates.add(amountWaterUsedAmountDto);
+
+                            }
+                        }
+
+                    }
+                    if (updates.size() > 0) {
+                        //List<List<AmountWaterUsedAmountDto>> lists = Lists.partition(updates, 500);
+                        for (AmountWaterUsedAmountDto amountWaterUsedAmountDto : updates) {
+                            amountWaterUsedAmountMapper.batchUpdate(amountWaterUsedAmountDto);
+                        }
+                    }
+                }
+
+
+                log.info("水量同步结束:" + LocalDateTime.now());
+
+            }
+
+        }
+
+
+    }*/
+}

+ 51 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/SmsService.java

@@ -0,0 +1,51 @@
+package com.bz.smart_city.service;
+
+import com.github.qcloudsms.SmsSingleSender;
+import com.github.qcloudsms.SmsSingleSenderResult;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+@Slf4j
+@Service
+public class SmsService {
+    @Value("${qcloudsms.appid}")
+    private Integer appid;
+
+    @Value("${qcloudsms.appkey}")
+    private String appkey;
+
+    void sendSms(String username, String phoneNumber, String password) {
+        // 短信模板ID,需要在短信应用中申请
+        int templateId = 308467;
+        // 签名
+        String smsSign = "佰众信息";
+        String[] params = {username, phoneNumber, password};//数组具体的元素个数和模板中变量个数必须一致,例如事例中templateId:5678对应一个变量,参数数组中元素个数也必须是一个
+        SmsSingleSender ssender = new SmsSingleSender(appid, appkey);
+        SmsSingleSenderResult result = null;  // 签名参数未提供或者为空时,会使用默认签名发送短信
+        try {
+            result = ssender.sendWithParam("86", phoneNumber,
+                    templateId, params, smsSign, "", "");
+        } catch (Exception e) {
+            log.info("sendSms Exception:" + e.getMessage());
+        }
+        log.info("sendSms redutl:" + result);
+    }
+
+    public void sendVerificationCodeSms(String phoneNumber, String code) {
+        // 短信模板ID,需要在短信应用中申请
+        int templateId = 342305;
+        // 签名
+        String smsSign = "佰众信息";
+        String[] params = {code, "15"};//数组具体的元素个数和模板中变量个数必须一致,例如事例中templateId:5678对应一个变量,参数数组中元素个数也必须是一个
+        SmsSingleSender ssender = new SmsSingleSender(appid, appkey);
+        SmsSingleSenderResult result = null;  // 签名参数未提供或者为空时,会使用默认签名发送短信
+        try {
+            result = ssender.sendWithParam("86", phoneNumber,
+                    templateId, params, smsSign, "", "");
+        } catch (Exception e) {
+            log.info("sendSms Exception:" + e.getMessage());
+        }
+        log.info("sendSms redutl:" + result);
+    }
+}

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

@@ -5,17 +5,20 @@ import com.bz.smart_city.commom.model.AjaxMessage;
 import com.bz.smart_city.commom.model.Pagination;
 import com.bz.smart_city.commom.model.ResultStatus;
 import com.bz.smart_city.commom.util.*;
+import com.bz.smart_city.dao.CustomerMapper;
 import com.bz.smart_city.dao.pay.*;
 import com.bz.smart_city.dao.pay.archives.PayBaseCustomerandmeterrelaMapper;
+import com.bz.smart_city.dto.CustomerDto;
 import com.bz.smart_city.dto.LoginUser;
 import com.bz.smart_city.dto.pay.*;
+import com.bz.smart_city.dto.pay.DeviceReplaceRecordDto;
 import com.bz.smart_city.entity.ProgramItem;
-import com.bz.smart_city.entity.Site;
 import com.bz.smart_city.entity.pay.*;
 import com.bz.smart_city.entity.pay.archives.PayBaseCustomerandmeterrela;
 import com.bz.smart_city.service.pay.AmountWaterUsedAmountService;
 import com.github.pagehelper.PageHelper;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -25,7 +28,6 @@ import javax.servlet.http.HttpServletResponse;
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.time.LocalDateTime;
-import java.time.Month;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.concurrent.*;
@@ -67,7 +69,8 @@ public class AmountWaterUsedAmountServiceImpl implements AmountWaterUsedAmountSe
     private PaySysDictMapper paySysDictMapper;
     @Resource
     private PayFeeMapper payFeeMapper;
-
+    @Resource
+    private CustomerMapper customerMapper;
 
     @Override
     public Pagination<AmountWaterUsedAmountDto> getList(String condition, String accountNumber, String accountName, String meterCode, String address, Integer year, Integer month, Integer state,
@@ -630,7 +633,6 @@ public class AmountWaterUsedAmountServiceImpl implements AmountWaterUsedAmountSe
                 if(ajaxMessage.getStatus()<0){
                     return 0;
                 }
-
             } catch (Exception e) {
                 e.printStackTrace();
             }
@@ -638,4 +640,53 @@ public class AmountWaterUsedAmountServiceImpl implements AmountWaterUsedAmountSe
         }
 
     }
+
+    @Override
+    public void saveDeviceReplaceRecord(DeviceReplaceRecordDto deviceReplaceRecordDto){
+        DeviceReplaceRecord deviceReplaceRecord=new DeviceReplaceRecord();
+        //根据客户编号查询出客户id、站点id
+        if(deviceReplaceRecordDto != null && StringUtils.isNotBlank(deviceReplaceRecordDto.getCustomerNo())){
+            CustomerDto customerDto = customerMapper.getCustomerByCustomerno(deviceReplaceRecordDto.getCustomerNo());
+            if(customerDto == null){
+                throw  new ServiceException(ResultStatus.CLEARING_DATA_QUERY_NO_CUSTOMER);
+            }
+            deviceReplaceRecord.setSiteId(customerDto.getSiteId());
+            deviceReplaceRecord.setCustomerId(customerDto.getId());
+        }else{
+            throw  new ServiceException(ResultStatus.LACK_NECESSARY_PARAM);
+        }
+        //查询当前账期
+        BaseClosingAccountInfoDto baseClosingAccountInfoDto = baseClosingAccountInfoMapper.getLastClosingAccount(deviceReplaceRecord.getSiteId(),deviceReplaceRecord.getCustomerId());
+
+        if(baseClosingAccountInfoDto != null
+            && baseClosingAccountInfoDto.getYear() != null
+            && baseClosingAccountInfoDto.getMonth() != null){
+            deviceReplaceRecord.setYear(baseClosingAccountInfoDto.getYear());
+            deviceReplaceRecord.setMonth(baseClosingAccountInfoDto.getMonth());
+        }else{
+            throw  new ServiceException(ResultStatus.CLEARING_DATA_QUERY_NO_ACCOUNT);
+        }
+        //查询水表上次抄表止度
+        AmountWaterUsedAmount amountWaterUsedAmount = amountWaterUsedAmountMapper.getLastReadrecord(deviceReplaceRecordDto.getMetercode(),deviceReplaceRecord.getSiteId(),deviceReplaceRecord.getCustomerId());
+        if(amountWaterUsedAmount == null || amountWaterUsedAmount.getAmount() == null){
+            //无上次抄表数据则取水表起度
+
+        }else{
+            deviceReplaceRecord.setOldLastreading(amountWaterUsedAmount.getAmount());
+        }
+        //计算出旧表水量
+        deviceReplaceRecord.setOldAmount(deviceReplaceRecordDto.getOldReading().subtract(deviceReplaceRecord.getOldLastreading()));
+        //换表信息
+
+        deviceReplaceRecord.setCreateDate(LocalDateTime.now());
+        deviceReplaceRecord.setMetercode(deviceReplaceRecordDto.getMetercode());
+        deviceReplaceRecord.setOldEleno(deviceReplaceRecordDto.getOldEleno());
+        deviceReplaceRecord.setNewEleno(deviceReplaceRecordDto.getNewEleno());
+        deviceReplaceRecord.setOldReading(deviceReplaceRecordDto.getOldReading());
+        deviceReplaceRecord.setNewStartcount(deviceReplaceRecordDto.getNewStartcount());
+        deviceReplaceRecord.setRemarks("换表同步");
+        amountWaterUsedAmountMapper.insertReplaceRecord(deviceReplaceRecord);
+
+    }
+
 }

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

@@ -4,6 +4,7 @@ package com.bz.smart_city.service.pay;
 import com.bz.smart_city.commom.model.AjaxMessage;
 import com.bz.smart_city.commom.model.Pagination;
 import com.bz.smart_city.dto.pay.AmountWaterUsedAmountDto;
+import com.bz.smart_city.dto.pay.DeviceReplaceRecordDto;
 import com.bz.smart_city.entity.pay.AmountWaterUsedAmount;
 
 import javax.servlet.http.HttpServletResponse;
@@ -25,4 +26,10 @@ public interface AmountWaterUsedAmountService {
 
     public AjaxMessage getAllCount(String condition,Integer year,Integer  month,
                                     Integer  state,Integer  amountMin,Integer  amountMax);
+
+    /**
+     * 同步换表记录
+     * @param deviceReplaceRecordDto
+     */
+    void saveDeviceReplaceRecord(DeviceReplaceRecordDto deviceReplaceRecordDto);
 }

+ 43 - 0
smart-city-platform/src/main/resources/mapper/AreaMapper.xml

@@ -0,0 +1,43 @@
+<?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.AreaMapper">
+  <resultMap id="BaseResultMap" type="com.bz.smart_city.entity.Area">
+    <!--
+      WARNING - @mbg.generated
+      This element is automatically generated by MyBatis Generator, do not modify.
+    -->
+    <result column="id" jdbcType="INTEGER" property="id" />
+    <result column="parent_id" jdbcType="INTEGER" property="parentId" />
+    <result column="name" jdbcType="VARCHAR" property="name" />
+    <result column="manger_name" jdbcType="VARCHAR" property="mangerName" />
+    <result column="short_name" jdbcType="VARCHAR" property="shortName" />
+    <result column="manger_short_name" jdbcType="VARCHAR" property="mangerShortName" />
+    <result column="level_type" jdbcType="TINYINT" property="levelType" />
+    <result column="city_code" jdbcType="CHAR" property="cityCode" />
+    <result column="zip_code" jdbcType="CHAR" property="zipCode" />
+    <result column="pin_yin" jdbcType="VARCHAR" property="pinYin" />
+    <result column="jian_pin" jdbcType="CHAR" property="jianPin" />
+    <result column="first_char" jdbcType="CHAR" property="firstChar" />
+    <result column="lng" jdbcType="VARCHAR" property="lng" />
+    <result column="lat" jdbcType="VARCHAR" property="lat" />
+    <result column="remark" jdbcType="VARCHAR" property="remark" />
+  </resultMap>
+
+
+    <select id="findByIds" resultMap="BaseResultMap">
+        select id,parent_id,name,level_type,lat,lng from sc_area where 1 = 1
+        <if test="ids != null">
+          and id in <foreach collection="ids" item="item" open="(" separator="," close=")">#{item}</foreach>
+        </if>
+    </select>
+
+	<select id="findByLevelType"
+		resultType="com.bz.smart_city.dto.AreaRelevanceDto">
+		select a1.id,a1.name ,a2.`name` as property1,a3.`name` as property2
+		from sc_area a1
+		LEFT JOIN sc_area a2 on(a2.id = a1.parent_id and a2.id != 100000)
+		LEFT JOIN sc_area a3 on(a3.id = a2.parent_id and a3.id != 100000)
+		where 1 = 1 and a1.level_type = #{levelType}
+	</select>
+
+</mapper>

+ 5 - 0
smart-city-platform/src/main/resources/mapper/CustomerMapper.xml

@@ -259,6 +259,11 @@
         select count(1) from sc_customer where status = 1 and parent_id = #{customerId}
     </select>
 
+    <select id="getCustomerByCustomerno" resultType="com.bz.smart_city.dto.CustomerDto">
+        select <include refid="Base_Column_List"></include> from sc_customer
+        where status = 1 and customer_no = #{customerNo}
+        order by date_create desc
+    </select>
 
 </mapper>
 

+ 45 - 0
smart-city-platform/src/main/resources/mapper/pay/AmountWaterUsedAmountMapper.xml

@@ -567,4 +567,49 @@
 		</where>
 
 	</select>
+
+	<select id="getLastReadrecord" resultType="com.bz.smart_city.dto.pay.AmountWaterUsedAmountDto">
+		SELECT
+		<include refid="amountWaterusedamountColumns"/>
+		FROM pay_amount_waterusedamount a
+		<include refid="amountWaterusedamountJoins"/>
+		where a.site_id = #{siteId} and a.customer_id = #{customerId}
+				and a.metercode = #{metercode} and a.state=2
+		order by a.approvetime desc
+		limit 1
+	</select>
+
+	<insert id="insertReplaceRecord">
+
+		insert into pay_device_replace_record
+		(
+			metercode,
+			old_eleno,
+			new_eleno,
+			old_lastreading,
+			old_reading,
+			old_amount,
+			new_startcount,
+			create_date,
+			remarks,
+			site_id,
+			customer_id,
+			year,
+			month)
+		value(
+			#{metercode},
+			#{oldEleno},
+			#{newEleno},
+			#{oldLastreading},
+			#{oldReading},
+			#{oldAmount},
+			#{new_startcount},
+			#{createDate},
+			#{remarks},
+			#{siteId},
+			#{customerId},
+			#{year},
+			#{month})
+	</insert>
+
 </mapper>