|
@@ -0,0 +1,292 @@
|
|
|
+package com.zcxk.rmcp.web.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.zcxk.core.common.enums.StatusEnum;
|
|
|
+import com.zcxk.core.common.pojo.LoginUser;
|
|
|
+import com.zcxk.core.common.util.BeanCopyUtils;
|
|
|
+import com.zcxk.core.common.util.SnowflakeIdWorker;
|
|
|
+import com.zcxk.core.common.util.UserUtil;
|
|
|
+import com.zcxk.core.mysql.pageing.Pagination;
|
|
|
+import com.zcxk.rmcp.api.dto.InstallDetailDto;
|
|
|
+import com.zcxk.rmcp.api.dto.InstallPlanDataDto;
|
|
|
+import com.zcxk.rmcp.api.dto.InstallPlanInputDto;
|
|
|
+import com.zcxk.rmcp.api.query.InstallPlanQueryCondition;
|
|
|
+import com.zcxk.rmcp.api.vo.InstallPlanVo;
|
|
|
+import com.zcxk.rmcp.core.dao.CommunityMapper;
|
|
|
+import com.zcxk.rmcp.core.dao.InstallListMapper;
|
|
|
+import com.zcxk.rmcp.core.dao.InstallPlanDataMapper;
|
|
|
+import com.zcxk.rmcp.core.entity.Community;
|
|
|
+import com.zcxk.rmcp.core.entity.InstallList;
|
|
|
+import com.zcxk.rmcp.core.entity.InstallPlanData;
|
|
|
+import com.zcxk.rmcp.web.service.CommunityService;
|
|
|
+import com.zcxk.rmcp.web.service.InstallListService;
|
|
|
+import com.zcxk.rmcp.web.service.InstallPlanAsyncService;
|
|
|
+import com.zcxk.rmcp.web.service.InstallPlanService;
|
|
|
+import com.zcxk.rmcp.web.util.TreeUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
+import com.zcxk.rmcp.core.dao.InstallPlanMapper;
|
|
|
+import com.zcxk.rmcp.core.entity.InstallPlan;
|
|
|
+import org.springframework.transaction.TransactionDefinition;
|
|
|
+import org.springframework.transaction.TransactionStatus;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import static com.google.common.collect.Lists.newArrayList;
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * @author linqingwei
|
|
|
+ * @date 2021-07-21 10:03
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class InstallPlanServiceImpl implements InstallPlanService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private InstallPlanMapper installPlanMapper;
|
|
|
+ @Resource
|
|
|
+ private CommunityMapper communityMapper;
|
|
|
+ @Autowired
|
|
|
+ private SnowflakeIdWorker idWorker;
|
|
|
+ @Resource
|
|
|
+ private InstallListMapper installListMapper;
|
|
|
+ @Resource
|
|
|
+ private InstallPlanDataMapper installPlanDataMapper;
|
|
|
+ @Autowired
|
|
|
+ private DataSourceTransactionManager dataSourceTransactionManager;
|
|
|
+ @Autowired
|
|
|
+ private TransactionDefinition transactionDefinition;
|
|
|
+ @Autowired
|
|
|
+ private InstallPlanAsyncService installPlanAsyncService;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int insertSelective(InstallPlan record) {
|
|
|
+ record.setDoorNum(0);
|
|
|
+ record.setInstallNum(0);
|
|
|
+ record.setAcceptedNum(0);
|
|
|
+ record.setPlanStatus(0);
|
|
|
+ record.setAcceptStatus(0);
|
|
|
+ record.setAcceptStatus(0);
|
|
|
+ record.setStatus(StatusEnum.OK.getCode());
|
|
|
+ record.setCreateBy(UserUtil.getUsername());
|
|
|
+ record.setCreateDate(LocalDateTime.now());
|
|
|
+ record.setUpdateBy(UserUtil.getUsername());
|
|
|
+ record.setUpdateDate(LocalDateTime.now());
|
|
|
+ return installPlanMapper.insertSelective(record);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int updateByPrimaryKeySelective(InstallPlan record) {
|
|
|
+ return installPlanMapper.updateByPrimaryKeySelective(record);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Pagination<InstallPlanVo> getPage(InstallPlanQueryCondition condition, int pageNum, int pageSize) {
|
|
|
+
|
|
|
+ PageHelper.startPage(pageNum,pageSize);
|
|
|
+ List<InstallPlanVo> list = installPlanMapper.findList(condition,UserUtil.getCurrentUser().getUserCondition());
|
|
|
+ return new Pagination<>(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void add(InstallPlanInputDto dto) {
|
|
|
+ log.info("begin InstallPlanServiceImpl add : " + JSON.toJSONString(dto));
|
|
|
+ LoginUser loginUser = UserUtil.getCurrentUser();
|
|
|
+
|
|
|
+ TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
|
|
|
+ Integer planId = null;
|
|
|
+ try {
|
|
|
+
|
|
|
+ // 1、小区更新
|
|
|
+ Community community = new Community();
|
|
|
+ community.setId(dto.getCommunityId());
|
|
|
+ community.setAddress(dto.getAdrress());
|
|
|
+ community.setLng(dto.getLng());
|
|
|
+ community.setLat(dto.getLat());
|
|
|
+ communityMapper.updateByPrimaryKeySelective(community);
|
|
|
+
|
|
|
+ // 2、保存计划
|
|
|
+ InstallPlan installPlan = new InstallPlan();
|
|
|
+ BeanCopyUtils.copyProperties(dto, installPlan, InstallPlan.class);
|
|
|
+ installPlan.setTenantId(loginUser.getTenantId());
|
|
|
+ installPlan.setPlatformType(1);
|
|
|
+ this.insertSelective(installPlan);
|
|
|
+
|
|
|
+ // 3、添加计划清单数据
|
|
|
+ addPlanData(installPlan.getId(),installPlan.getTenantId(),dto);
|
|
|
+ planId = installPlan.getId();
|
|
|
+
|
|
|
+ dataSourceTransactionManager.commit(transactionStatus);
|
|
|
+ }catch (Exception e){
|
|
|
+ dataSourceTransactionManager.rollback(transactionStatus);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 4、异步生成压缩文件
|
|
|
+ InstallPlan installPlan = installPlanMapper.findById(planId);
|
|
|
+ installPlanAsyncService.asyncTaskToZip(loginUser, installPlan);
|
|
|
+
|
|
|
+ log.info("end InstallPlanServiceImpl add");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addPlanData(Integer planId, String tenantId, InstallPlanInputDto dto){
|
|
|
+ int doorNum = 0;
|
|
|
+ List<InstallPlanDataDto> list = dto.getInstallPlanDataList();
|
|
|
+ if (list != null && list.size() > 0) {
|
|
|
+ List<InstallList> installLists = newArrayList();
|
|
|
+ List<InstallPlanData> installPlanDataList = newArrayList();
|
|
|
+ for (InstallPlanDataDto installPlanBuilding : list) {
|
|
|
+ InstallPlanData installPlanDataBuilding = new InstallPlanData();
|
|
|
+ installPlanDataBuilding.setId(idWorker.nextId());
|
|
|
+ installPlanDataBuilding.setName(installPlanBuilding.getName() + "栋");
|
|
|
+ installPlanDataBuilding.setParentId(0L);
|
|
|
+ installPlanDataBuilding.setInstallPlanId(planId);
|
|
|
+ installPlanDataBuilding.setType(1);
|
|
|
+ installPlanDataBuilding.setStatus(1);
|
|
|
+ installPlanDataList.add(installPlanDataBuilding);
|
|
|
+ //单元
|
|
|
+ if (installPlanBuilding.getChildren() != null && installPlanBuilding.getChildren().size() > 0) {
|
|
|
+ for (InstallPlanDataDto installPlanUnit : installPlanBuilding.getChildren()) {
|
|
|
+ InstallPlanData installPlanDataUnit = new InstallPlanData();
|
|
|
+ installPlanDataUnit.setName(installPlanUnit.getName() != null ? installPlanUnit.getName() + "单元" : "");
|
|
|
+ installPlanDataUnit.setId(idWorker.nextId());
|
|
|
+ installPlanDataUnit.setParentId(installPlanDataBuilding.getId());
|
|
|
+ installPlanDataUnit.setInstallPlanId(planId);
|
|
|
+ installPlanDataUnit.setType(2);
|
|
|
+ installPlanDataUnit.setStatus(1);
|
|
|
+ installPlanDataList.add(installPlanDataUnit);
|
|
|
+
|
|
|
+ //安装楼层
|
|
|
+ if (installPlanUnit.getChildren() != null && installPlanUnit.getChildren().size() > 0) {
|
|
|
+ for (InstallPlanDataDto installPlanFloor : installPlanUnit.getChildren()) {
|
|
|
+ InstallPlanData installPlanDataFloor = new InstallPlanData();
|
|
|
+ installPlanDataFloor.setName(installPlanFloor.getName() + "层");
|
|
|
+ installPlanDataFloor.setId(idWorker.nextId());
|
|
|
+ installPlanDataFloor.setParentId(installPlanDataUnit.getId());
|
|
|
+ installPlanDataFloor.setInstallPlanId(planId);
|
|
|
+ installPlanDataFloor.setType(3);
|
|
|
+ installPlanDataFloor.setStatus(1);
|
|
|
+ installPlanDataList.add(installPlanDataFloor);
|
|
|
+ //安装清单
|
|
|
+ if (installPlanFloor.getChildren() != null && installPlanFloor.getChildren().size() > 0) {
|
|
|
+ for (InstallPlanDataDto installPlanDoor : installPlanFloor.getChildren()) {
|
|
|
+ InstallList installList = new InstallList();
|
|
|
+ installList.setTenantId(tenantId);
|
|
|
+ installList.setInstallPlanId(planId);
|
|
|
+ installList.setInstallPlanDataId(installPlanDataFloor.getId());
|
|
|
+ installList.setDoorNo(installPlanDoor.getName());
|
|
|
+ installList.setIsInstalled(0);
|
|
|
+ installList.setIsAccepted(0);
|
|
|
+
|
|
|
+ installList.setRemark("");
|
|
|
+ installList.setStatus(StatusEnum.OK.getCode());
|
|
|
+ installList.setCreateDate(LocalDateTime.now());
|
|
|
+ installList.setUpdateDate(LocalDateTime.now());
|
|
|
+ installList.setCreateBy(UserUtil.getUsername());
|
|
|
+ installList.setUpdateBy(UserUtil.getUsername());
|
|
|
+ installLists.add(installList);
|
|
|
+ doorNum++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ installListMapper.batchInsert(installLists);
|
|
|
+ installPlanDataMapper.batchInsert(installPlanDataList);
|
|
|
+ }
|
|
|
+ //更新数量
|
|
|
+ InstallPlan updateInstallPlan = new InstallPlan();
|
|
|
+ updateInstallPlan.setId(planId);
|
|
|
+ updateInstallPlan.setDoorNum(doorNum);
|
|
|
+ this.updateByPrimaryKeySelective(updateInstallPlan);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void batchDel(List<Integer> ids) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void allDel(InstallPlanQueryCondition condition) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public InstallDetailDto getInstallDetail(Integer id) {
|
|
|
+ InstallDetailDto installDetail = new InstallDetailDto();
|
|
|
+ List<InstallPlanDataDto> installPlanDataDTOList = newArrayList();
|
|
|
+
|
|
|
+ //1、计划信息
|
|
|
+ InstallPlan installPlan = installPlanMapper.findById(id);
|
|
|
+ if (installPlan != null) {
|
|
|
+ installDetail.setCommunityName(installPlan.getPlanName());
|
|
|
+ installDetail.setEnableUnit(installPlan.getEnableUnit());
|
|
|
+ }
|
|
|
+
|
|
|
+ //2、计划数据(楼栋、单元、楼层)
|
|
|
+ List<InstallPlanData> installPlanDataList = installPlanDataMapper.fondByPlanId(id);
|
|
|
+ if (installPlanDataList != null && installPlanDataList.size() > 0) {
|
|
|
+ for (InstallPlanData installPlanData : installPlanDataList) {
|
|
|
+ InstallPlanDataDto installPlanDataDTO = new InstallPlanDataDto();
|
|
|
+ installPlanDataDTO.setId(installPlanData.getId());
|
|
|
+ installPlanDataDTO.setParentId(installPlanData.getParentId());
|
|
|
+ installPlanDataDTO.setName(installPlanData.getName());
|
|
|
+ installPlanDataDTO.setType(installPlanData.getType());
|
|
|
+ installPlanDataDTOList.add(installPlanDataDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //3、计划清单
|
|
|
+ List<InstallList> installLists = installListMapper.getInstallList(id);
|
|
|
+ if (installLists != null && installLists.size() > 0) {
|
|
|
+ Integer installedNumber = 0;
|
|
|
+ for (InstallList installList : installLists) {
|
|
|
+ InstallPlanDataDto installPlanDataDTO = new InstallPlanDataDto();
|
|
|
+ installPlanDataDTO.setId(Long.valueOf(installList.getId()));
|
|
|
+ installPlanDataDTO.setParentId(installList.getInstallPlanDataId());
|
|
|
+ installPlanDataDTO.setName(installList.getDoorNo());
|
|
|
+ installPlanDataDTO.setType(4);
|
|
|
+ installPlanDataDTO.setIsInstalled(installList.getIsInstalled());
|
|
|
+ installPlanDataDTO.setIsAccepted(installList.getIsAccepted());
|
|
|
+ installPlanDataDTOList.add(installPlanDataDTO);
|
|
|
+ if (installList.getIsInstalled() == 1) {
|
|
|
+ installedNumber++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ installDetail.setTotalNumber(installLists.size());
|
|
|
+ installDetail.setInstalledNumber(installedNumber);
|
|
|
+ }
|
|
|
+
|
|
|
+ //4、组装树形数据
|
|
|
+ List<InstallPlanDataDto> list = TreeUtil.getInstallPlanDataTree(installPlanDataDTOList, 0L, 1);
|
|
|
+ TreeUtil.postorderTraversal(list);
|
|
|
+ installDetail.setInstallPlanDataList(list);
|
|
|
+
|
|
|
+
|
|
|
+ return installDetail;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void downPlanTemplate(HttpServletResponse response) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void downInstallTemplate(Integer id, HttpServletResponse response) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|