|
@@ -0,0 +1,267 @@
|
|
|
+package com.bz.smart_city.service.impl.pay;
|
|
|
+
|
|
|
+import com.bz.smart_city.commom.model.AjaxMessage;
|
|
|
+import com.bz.smart_city.commom.model.ResultStatus;
|
|
|
+import com.bz.smart_city.commom.util.HttpRequest;
|
|
|
+import com.bz.smart_city.commom.util.JacksonUtil;
|
|
|
+import com.bz.smart_city.commom.util.SnowflakeIdWorker;
|
|
|
+import com.bz.smart_city.commom.util.UserUtil;
|
|
|
+import com.bz.smart_city.dao.DeviceMapper;
|
|
|
+import com.bz.smart_city.dao.WaterMeterReplaceLogMapper;
|
|
|
+import com.bz.smart_city.dto.AreaDto;
|
|
|
+import com.bz.smart_city.dto.CommunityDto;
|
|
|
+import com.bz.smart_city.dto.DeviceTypeDto;
|
|
|
+import com.bz.smart_city.dto.LoginUser;
|
|
|
+import com.bz.smart_city.dto.pay.InstallPlanDataDTO;
|
|
|
+import com.bz.smart_city.dto.pay.InstallPlanInputDTO;
|
|
|
+import com.bz.smart_city.dto.pay.PayBaseAccountDto;
|
|
|
+import com.bz.smart_city.dto.pay.PayBaseConfigDto;
|
|
|
+import com.bz.smart_city.entity.Community;
|
|
|
+import com.bz.smart_city.entity.Device;
|
|
|
+import com.bz.smart_city.entity.WaterMeterReplaceLog;
|
|
|
+import com.bz.smart_city.service.CommunityService;
|
|
|
+import com.bz.smart_city.service.pay.PayBaseAccountService;
|
|
|
+import com.bz.smart_city.service.pay.PayBaseConfigService;
|
|
|
+import com.bz.smart_city.service.pay.PaySyncDataService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.math.BigInteger;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import static com.google.common.collect.Lists.newArrayList;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by ZJY on 2020-09-27 15:29
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class PaySyncDataServiceImpl implements PaySyncDataService {
|
|
|
+ @Autowired
|
|
|
+ private CommunityService communityService;
|
|
|
+ @Autowired
|
|
|
+ private SnowflakeIdWorker idWorker;
|
|
|
+ @Autowired
|
|
|
+ private PayBaseAccountService payBaseAccountService;
|
|
|
+ @Autowired
|
|
|
+ private PayBaseConfigService payBaseConfigService;
|
|
|
+ @Resource
|
|
|
+ DeviceMapper deviceMapper;
|
|
|
+ @Value("${Sync.Data.Url}")
|
|
|
+ String SyncUrl;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ WaterMeterReplaceLogMapper waterMeterReplaceLogMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AjaxMessage<List<AreaDto>> getAllArea(){
|
|
|
+
|
|
|
+ //调用接口
|
|
|
+ String url=SyncUrl + "/api/common/getAllArea";
|
|
|
+ try {
|
|
|
+ String result = HttpRequest.doGet(url);
|
|
|
+
|
|
|
+ AjaxMessage<List<AreaDto>> ajaxMessage = JacksonUtil.string2Obj(result, AjaxMessage.class);
|
|
|
+
|
|
|
+ return ajaxMessage;
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println(e.getMessage());
|
|
|
+
|
|
|
+ return new AjaxMessage(ResultStatus.ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AjaxMessage<List<DeviceTypeDto>> queryWaterMeterType(Integer parentId){
|
|
|
+ String url = SyncUrl + "/api/mobile/assistant/getMeterTypes";
|
|
|
+
|
|
|
+ try {
|
|
|
+ if(parentId != null){
|
|
|
+ url += String.format("?parentId=%d",parentId);
|
|
|
+ }
|
|
|
+ String result = HttpRequest.doGet(url);
|
|
|
+
|
|
|
+ AjaxMessage<List<DeviceTypeDto>> ajaxMessage =JacksonUtil.string2Obj(result,AjaxMessage.class);
|
|
|
+ return ajaxMessage;
|
|
|
+ }
|
|
|
+ catch (Exception e){
|
|
|
+ return new AjaxMessage(ResultStatus.ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AjaxMessage<List<CommunityDto>> queryCommunity(Community param){
|
|
|
+
|
|
|
+ String url = SyncUrl+"/api/syncData/queryCommunityByName";
|
|
|
+ try {
|
|
|
+ String json = JacksonUtil.obj2String(param);
|
|
|
+ String result = HttpRequest.doPost(url,json);
|
|
|
+ AjaxMessage<List<CommunityDto>> ajaxMessage = JacksonUtil.string2Obj(result,AjaxMessage.class);
|
|
|
+ return ajaxMessage;
|
|
|
+ }
|
|
|
+ catch (Exception e){
|
|
|
+ return new AjaxMessage(ResultStatus.ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int addReplaceRecord(WaterMeterReplaceLog waterMeterReplaceLog){
|
|
|
+ return waterMeterReplaceLogMapper.insertSelective(waterMeterReplaceLog);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public AjaxMessage addJF(InstallPlanInputDTO installPlanInput){
|
|
|
+
|
|
|
+ LoginUser loginUser = UserUtil.getCurrentUser();
|
|
|
+ Integer siteId = 1;
|
|
|
+ if (loginUser.getSiteType() == 1) {
|
|
|
+ siteId = loginUser.getSiteId();
|
|
|
+ }
|
|
|
+ installPlanInput.setPlatformType(2);
|
|
|
+
|
|
|
+ //取客户编码
|
|
|
+ String customerNo="";
|
|
|
+ List<PayBaseConfigDto> payBaseConfigDtos = payBaseConfigService.getPrintInfo("CUSTOMER_NO",loginUser.getSiteId(),loginUser.getCustomerId());
|
|
|
+ for (PayBaseConfigDto item : payBaseConfigDtos){
|
|
|
+ if(item.getName().trim()=="CUSTOMER_NO"){
|
|
|
+ customerNo = item.getValue();
|
|
|
+ installPlanInput.setCustomerNo(customerNo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //1、小区
|
|
|
+ String code = "001";
|
|
|
+ String address = "";
|
|
|
+ String communityAndBuildingAndUnitAddress=""; //小区 楼栋 单元地址
|
|
|
+ String floorAddress="";
|
|
|
+ String doorAddress="";
|
|
|
+ if (1==1) {
|
|
|
+ Community community = communityService.findByNameV2(siteId,installPlanInput.getProvince(),installPlanInput.getCity(),installPlanInput.getRegion(), installPlanInput.getCommunityName());
|
|
|
+ if (community != null) {
|
|
|
+ installPlanInput.setCommunityId(community.getId());
|
|
|
+ } else {
|
|
|
+ Community newCommunity = new Community();
|
|
|
+ //获取小区最大值,然后加1
|
|
|
+ List<Community> communities = communityService.getMaxCodeBySiteId(siteId);
|
|
|
+ if(communities.size()==1)
|
|
|
+ {
|
|
|
+ if (communities.get(0) != null) {
|
|
|
+ code =String.format("%03d",Integer.valueOf(communities.get(0).getCode()));
|
|
|
+ }else {
|
|
|
+ code = String.format("%03d",Integer.valueOf("1"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ newCommunity.setCode(code);
|
|
|
+ newCommunity.setSiteId(siteId);
|
|
|
+ newCommunity.setName(installPlanInput.getCommunityName());
|
|
|
+ newCommunity.setProvince(installPlanInput.getProvince());
|
|
|
+ newCommunity.setCity(installPlanInput.getCity());
|
|
|
+ newCommunity.setRegion(installPlanInput.getRegion());
|
|
|
+ newCommunity.setAddress(installPlanInput.getAdrress());
|
|
|
+ newCommunity.setCustomerId(installPlanInput.getCustomerId());
|
|
|
+ newCommunity.setStatus(1);
|
|
|
+ communityService.insert(newCommunity);
|
|
|
+ //installPlanInput.setCommunityId(newCommunity.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ int maxAccountNumber = payBaseAccountService.getMaxAccountNumber(code);
|
|
|
+
|
|
|
+ //楼栋
|
|
|
+ if (installPlanInput.getInstallPlanDataList() != null && installPlanInput.getInstallPlanDataList().size() > 0) {
|
|
|
+ List<PayBaseAccountDto> accountLists = newArrayList();
|
|
|
+
|
|
|
+ for (InstallPlanDataDTO installPlanBuilding : installPlanInput.getInstallPlanDataList()) {
|
|
|
+ //单元
|
|
|
+ if (installPlanBuilding.getChildren() != null && installPlanBuilding.getChildren().size() > 0) {
|
|
|
+ for (InstallPlanDataDTO installPlanUnit : installPlanBuilding.getChildren()) {
|
|
|
+
|
|
|
+ //判断是否启动单元
|
|
|
+ String buildingName = "";
|
|
|
+ if (installPlanInput.getEnableUnit() == 1) {
|
|
|
+ buildingName = installPlanInput.getCommunityName() + installPlanBuilding.getName() + "栋" + installPlanUnit.getName() + "单元";
|
|
|
+ } else {
|
|
|
+ buildingName = installPlanInput.getCommunityName() + installPlanBuilding.getName() + "栋";
|
|
|
+ }
|
|
|
+ communityAndBuildingAndUnitAddress = buildingName;
|
|
|
+
|
|
|
+
|
|
|
+ //安装楼层
|
|
|
+ if (installPlanUnit.getChildren() != null && installPlanUnit.getChildren().size() > 0) {
|
|
|
+ for (InstallPlanDataDTO installPlanFloor : installPlanUnit.getChildren()) {
|
|
|
+ floorAddress = (installPlanFloor.getName() + "层");
|
|
|
+
|
|
|
+ //安装清单
|
|
|
+ if (installPlanFloor.getChildren() != null && installPlanFloor.getChildren().size() > 0) {
|
|
|
+ for (InstallPlanDataDTO installPlanDoor : installPlanFloor.getChildren()) {
|
|
|
+
|
|
|
+ //添加客户信息(水表用户)
|
|
|
+ doorAddress = (installPlanDoor.getName());
|
|
|
+ long accountid = idWorker.nextId();
|
|
|
+ PayBaseAccountDto payBaseAccountDto = new PayBaseAccountDto();
|
|
|
+ payBaseAccountDto.setId(BigInteger.valueOf(accountid));
|
|
|
+ payBaseAccountDto.setCalculateway(installPlanInput.getCalculateway_id());
|
|
|
+ if (installPlanInput.getWaterproperty_id() != null)
|
|
|
+ payBaseAccountDto.setWaterpropertyId(installPlanInput.getWaterproperty_id());
|
|
|
+ else
|
|
|
+ payBaseAccountDto.setWaterpropertyId(null);
|
|
|
+ payBaseAccountDto.setCommunityCode(code);
|
|
|
+ payBaseAccountDto.setAddress(communityAndBuildingAndUnitAddress + floorAddress + doorAddress);
|
|
|
+
|
|
|
+ ++maxAccountNumber;
|
|
|
+ String strAccountNumber = String.format("%s%07d", code, (maxAccountNumber));
|
|
|
+ payBaseAccountDto.setAccountnumber(strAccountNumber);
|
|
|
+ accountLists.add(payBaseAccountDto);
|
|
|
+
|
|
|
+ installPlanDoor.setFileNo(strAccountNumber);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //调用接口
|
|
|
+ String url = SyncUrl + "/api/syncData/syncPlan";
|
|
|
+ try {
|
|
|
+ String json = JacksonUtil.obj2String(installPlanInput);
|
|
|
+ String result = HttpRequest.doPost(url,json);
|
|
|
+ AjaxMessage ajaxMessage = JacksonUtil.string2Obj(result,AjaxMessage.class);
|
|
|
+ if(ajaxMessage != null && ajaxMessage.getStatus() == 0){
|
|
|
+
|
|
|
+ //生成用户信息和预存账户
|
|
|
+ payBaseAccountService.batchInsert(accountLists, code);
|
|
|
+
|
|
|
+ //生成水表信息(sc_device表)
|
|
|
+ List<Device> deviceList = new ArrayList<>();
|
|
|
+ for (PayBaseAccountDto payBaseAccount : accountLists){
|
|
|
+ long deviceId = idWorker.nextId();
|
|
|
+ Device device = new Device();
|
|
|
+ device.setId(deviceId);
|
|
|
+ device.setMetercode(payBaseAccount.getAccountnumber());
|
|
|
+ device.setAccountId(payBaseAccount.getId());
|
|
|
+ deviceList.add(device);
|
|
|
+ }
|
|
|
+ deviceMapper.insertList(deviceList);
|
|
|
+
|
|
|
+ return ajaxMessage;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception e){
|
|
|
+ return new AjaxMessage(ResultStatus.ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ return new AjaxMessage(ResultStatus.ERROR);
|
|
|
+ }
|
|
|
+}
|