| | |
| | | package cn.gistack.sm.sjztmd.service.impl; |
| | | |
| | | import cn.gistack.sm.sjztmd.entity.TbAttResRsbVerspi; |
| | | import cn.gistack.sm.sjztmd.entity.TbFileStorageLocation; |
| | | import cn.gistack.sm.sjztmd.entity.TbRelResUser; |
| | | import cn.gistack.sm.sjztmd.entity.TbResStagCapDisc; |
| | | import cn.gistack.sm.sjztmd.excel.TbRelResUserExcel; |
| | | import cn.gistack.sm.sjztmd.excel.TbResStagCapDiscImportExcel; |
| | | import cn.gistack.sm.sjztmd.mapper.TbRelResUserMapper; |
| | | import cn.gistack.sm.sjztmd.mapper.TbResStagCapDiscMapper; |
| | | import cn.gistack.sm.sjztmd.service.ITbAttResBaseService; |
| | | import cn.gistack.sm.sjztmd.service.ITbResStagCapDiscService; |
| | | import cn.gistack.sm.sjztmd.util.CalculateUtils; |
| | | import cn.gistack.system.user.feign.IUserClient; |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.context.AnalysisContext; |
| | | import com.alibaba.excel.event.AnalysisEventListener; |
| | | import com.baomidou.dynamic.datasource.annotation.DS; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.springblade.core.mp.support.Condition; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.utils.BeanUtil; |
| | | import org.springblade.core.tool.utils.DateUtil; |
| | | import org.springblade.core.tool.utils.ObjectUtil; |
| | | import org.springblade.core.tool.utils.StringUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.InputStream; |
| | | import java.math.BigDecimal; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | @DS("zt") |
| | |
| | | private ITbAttResBaseService tbAttResBaseService; |
| | | |
| | | @Override |
| | | public Boolean addAll(List<TbResStagCapDisc> list) { |
| | | //先把该水库的数据全部删除 |
| | | String resGuid = list.get(0).getResGuid(); |
| | | |
| | | baseMapper.deleteByResGuid(resGuid); |
| | | Date now = DateUtil.now(); |
| | | public Boolean addAll(List<TbResStagCapDisc> newList) { |
| | | boolean edit = false; |
| | | // 编辑标记 |
| | | if (newList.get(0).getCheckState()==4){ |
| | | edit = true; |
| | | } |
| | | // 查询是否存在 |
| | | List<TbResStagCapDisc> oldList = baseMapper.getDetailByResGuid(newList.get(0).getResGuid()); |
| | | // 更新日志 |
| | | setUpdateLog(oldList,newList); |
| | | // 创建或更新数据 |
| | | boolean flag = addOrUpdate(oldList,newList); |
| | | if (flag){ |
| | | // if (!edit) { |
| | | // tbAttResBaseService.updateFinalState(newList.get(0).getResGuid(), 0); |
| | | // } |
| | | return true; |
| | | } |
| | | // 返回 |
| | | return false; |
| | | |
| | | |
| | | //循环数组 |
| | | list.forEach(tbResStagCapDisc -> { |
| | | //如果guid为空表示新增数据 |
| | | if (StringUtil.isBlank(tbResStagCapDisc.getGuid())){ |
| | | tbResStagCapDisc.setCreateTime(now); |
| | | tbResStagCapDisc.setUpdateTime(now); |
| | | //更新操作日志 |
| | | setUpdateLog(tbResStagCapDisc,tbResStagCapDisc); |
| | | baseMapper.insert(tbResStagCapDisc); |
| | | }else{ |
| | | //更新数据 |
| | | tbResStagCapDisc.setUpdateTime(now); |
| | | //更新操作日志 |
| | | setUpdateLog(tbResStagCapDisc,tbResStagCapDisc); |
| | | baseMapper.insert(tbResStagCapDisc); |
| | | } |
| | | }); |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 查询水库填报详情信息 |
| | | * @param resGuid |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<TbResStagCapDisc> getDetailByResGuid(String resGuid) { |
| | | return baseMapper.getDetailByResGuid(resGuid); |
| | | } |
| | | |
| | | @Override |
| | | public void importTbResStagCapDisc(List<TbResStagCapDiscImportExcel> data,String resGuid) { |
| | | |
| | | for (int i = 0; i < data.size(); i++) { |
| | | TbResStagCapDiscImportExcel excel = data.get(0); |
| | | TbResStagCapDisc tbResStagCapDisc = Objects.requireNonNull(BeanUtil.copy(excel, TbResStagCapDisc.class)); |
| | | tbResStagCapDisc.setResGuid(resGuid); |
| | | double order = (double) i + 1; |
| | | tbResStagCapDisc.setOrderId(order); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public List<TbResStagCapDisc> readExcel(MultipartFile file) { |
| | | List<TbResStagCapDiscImportExcel> excelList = new ArrayList<>(); |
| | | try (InputStream inputStream = file.getInputStream()) { |
| | | EasyExcel.read(inputStream, TbResStagCapDiscImportExcel.class, new AnalysisEventListener<TbResStagCapDiscImportExcel>() { |
| | | @Override |
| | | public void invoke(TbResStagCapDiscImportExcel excelData, AnalysisContext analysisContext) { |
| | | excelList.add(excelData); |
| | | } |
| | | @Override |
| | | public void doAfterAllAnalysed(AnalysisContext analysisContext) { |
| | | // 所有数据解析完成后的回调 |
| | | } |
| | | }).sheet().doRead(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | // 处理异常,例如返回错误消息给前端 |
| | | } |
| | | |
| | | List<TbResStagCapDisc> resultList = new ArrayList<>(); |
| | | for (int i = 0; i < excelList.size(); i++) { |
| | | TbResStagCapDiscImportExcel excel = excelList.get(0); |
| | | TbResStagCapDisc tbResStagCapDisc = Objects.requireNonNull(BeanUtil.copy(excel, TbResStagCapDisc.class)); |
| | | double order = (double) i + 1; |
| | | tbResStagCapDisc.setOrderId(order); |
| | | resultList.add(tbResStagCapDisc); |
| | | } |
| | | |
| | | |
| | | return resultList; |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Boolean auditByGuid(List<TbResStagCapDisc> list) { |
| | | boolean b = false; |
| | | public Boolean auditByGuid(List<TbResStagCapDisc> newList) { |
| | | boolean edit = false; |
| | | // 编辑标记 |
| | | if (list.get(0).getCheckState()==4){ |
| | | if (newList.get(0).getCheckState()==4){ |
| | | edit = true; |
| | | } |
| | | |
| | | for (int i = 0; i < list.size(); i++) { |
| | | |
| | | TbResStagCapDisc tbResStagCapDisc = list.get(i); |
| | | |
| | | //更新操作日志 |
| | | setUpdateLog(tbResStagCapDisc,tbResStagCapDisc); |
| | | |
| | | //更新审核日志 |
| | | setUpdateCheckLog(tbResStagCapDisc,tbResStagCapDisc); |
| | | |
| | | // 驳回情况下将状态修改回0即已填写未提交状态 |
| | | if (tbResStagCapDisc.getCheckState()==3){ |
| | | tbResStagCapDisc.setCheckState(0); |
| | | } |
| | | |
| | | Date now = DateUtil.now(); |
| | | //更新数据 |
| | | tbResStagCapDisc.setUpdateTime(now); |
| | | updateById(tbResStagCapDisc); |
| | | } |
| | | |
| | | // if (b){ |
| | | // 查询是否存在 |
| | | List<TbResStagCapDisc> oldList = baseMapper.getDetailByResGuid(newList.get(0).getResGuid()); |
| | | // 更新操作日志 |
| | | setUpdateLog(oldList,newList); |
| | | // 更新审核日志 |
| | | setUpdateCheckLog(oldList,newList); |
| | | // 更新数据 |
| | | boolean batch = updateBatchById(newList); |
| | | if (batch){ |
| | | // if (!edit) { |
| | | // tbAttResBaseService.updateFinalState(list.get(0).getResGuid(), list.get(0).getCheckState()); |
| | | // tbAttResBaseService.updateFinalState(newList.get(0).getResGuid(), newList.get(0).getCheckState()); |
| | | // } |
| | | // return true; |
| | | // } |
| | | |
| | | return true; |
| | | return true; |
| | | } |
| | | // 返回 |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * @param older |
| | | * @param newer |
| | | * @param oldList |
| | | * @param newList |
| | | * 更新审核记录 |
| | | */ |
| | | private void setUpdateCheckLog(TbResStagCapDisc older, TbResStagCapDisc newer) { |
| | | String fillName = ""; |
| | | if (newer.getCheckState()==2){ |
| | | fillName = "审核"; |
| | | } |
| | | if (newer.getCheckState()==3){ |
| | | fillName = "退回" + (null==newer.getReason()?"":":" + newer.getReason()); |
| | | } |
| | | private void setUpdateCheckLog(List<TbResStagCapDisc> oldList,List<TbResStagCapDisc> newList) { |
| | | // 遍历 |
| | | for (TbResStagCapDisc newer : newList) { |
| | | String fillName = ""; |
| | | if (newer.getCheckState() == 2) { |
| | | fillName = "审核"; |
| | | } |
| | | if (newer.getCheckState() == 3) { |
| | | fillName = "退回" + (null == newer.getCheckLog() ? "" : ":" + newer.getCheckLog()); |
| | | for (TbResStagCapDisc older : oldList) { |
| | | if (older.getGuid().equals(newer.getGuid())){ |
| | | // 退回时进行设置状态为填写中 |
| | | newer.setCheckState(0); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 拼接 |
| | | String time = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date()); |
| | | String userName = AuthUtil.getUser().getUserName(); |
| | | String phone = userClient.userInfoById(AuthUtil.getUserId()).getData().getPhone(); |
| | | StringBuilder builder = new StringBuilder(); |
| | | builder.append(time) |
| | | .append(",") |
| | | .append(fillName) |
| | | .append(",") |
| | | .append(userName) |
| | | .append(",") |
| | | .append(phone) |
| | | .append(";"); |
| | | // 判断是否存在 |
| | | if (null==older){ |
| | | // 填报 |
| | | newer.setCheckLog(builder.toString()); |
| | | }else { |
| | | StringBuilder stringBuilder = new StringBuilder(null==older.getCheckLog()?"":older.getCheckLog()); |
| | | stringBuilder.append(builder); |
| | | // 填报 |
| | | newer.setCheckLog(stringBuilder.toString()); |
| | | // 拼接 |
| | | String time = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date()); |
| | | String userName = AuthUtil.getUser().getUserName(); |
| | | String phone = userClient.userInfoById(AuthUtil.getUserId()).getData().getPhone(); |
| | | StringBuilder builder = new StringBuilder(); |
| | | builder.append(time) |
| | | .append(",") |
| | | .append(fillName) |
| | | .append(",") |
| | | .append(userName) |
| | | .append(",") |
| | | .append(phone) |
| | | .append(";"); |
| | | // 判断是否存在 |
| | | if (null==newer.getGuid() || newer.getGuid().equals("")){ |
| | | // 填报 |
| | | newer.setCheckLog(builder.toString()); |
| | | } else { |
| | | for (TbResStagCapDisc older : oldList) { |
| | | if (older.getGuid().equals(newer.getGuid())){ |
| | | StringBuilder stringBuilder = new StringBuilder(null == older.getCheckLog() ? "" : older.getCheckLog()); |
| | | stringBuilder.append(builder); |
| | | // 填报 |
| | | newer.setCheckLog(stringBuilder.toString()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @param older |
| | | * @param newer |
| | | * @param oldList |
| | | * @param newList |
| | | * 更新操作记录 |
| | | */ |
| | | private void setUpdateLog(TbResStagCapDisc older,TbResStagCapDisc newer) { |
| | | String fillName = ""; |
| | | if (newer.getCheckState()==0){ |
| | | fillName = "编辑"; |
| | | } |
| | | if (newer.getCheckState()==1){ |
| | | fillName = "提交"; |
| | | } |
| | | if (newer.getCheckState()==2){ |
| | | fillName = "审核"; |
| | | } |
| | | if (newer.getCheckState()==3){ |
| | | fillName = "退回" + (null==newer.getCheckLog()?"":":" + newer.getCheckLog()); |
| | | } |
| | | if (newer.getCheckState()==4){ |
| | | fillName = "编辑"; |
| | | newer.setCheckState(older.getCheckState()); |
| | | } |
| | | private void setUpdateLog(List<TbResStagCapDisc> oldList,List<TbResStagCapDisc> newList) { |
| | | // 遍历 |
| | | for (TbResStagCapDisc newer : newList){ |
| | | String fillName = ""; |
| | | if (newer.getCheckState()==0){ |
| | | fillName = "编辑"; |
| | | } |
| | | if (newer.getCheckState()==1){ |
| | | fillName = "提交"; |
| | | } |
| | | if (newer.getCheckState()==2){ |
| | | fillName = "审核"; |
| | | } |
| | | if (newer.getCheckState()==3){ |
| | | fillName = "退回" + (null==newer.getCheckLog()?"":":" + newer.getCheckLog()); |
| | | } |
| | | // 管理员编辑 |
| | | if (newer.getCheckState()==4){ |
| | | fillName = "编辑"; |
| | | // 找到相关的 guid 数据 |
| | | if (oldList.size()>0){ |
| | | newer.setCheckState(oldList.get(0).getCheckState()); |
| | | } |
| | | } |
| | | |
| | | // 拼接 |
| | | String time = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date()); |
| | | String userName = AuthUtil.getUser().getUserName(); |
| | | String phone = userClient.userInfoById(AuthUtil.getUserId()).getData().getPhone(); |
| | | StringBuilder builder = new StringBuilder(); |
| | | builder.append(time) |
| | | .append(",") |
| | | .append(fillName) |
| | | .append(",") |
| | | .append(userName) |
| | | .append(",") |
| | | .append(phone) |
| | | .append(";"); |
| | | // 判断是否存在 |
| | | if (null==older){ |
| | | // 填报 |
| | | newer.setLog(builder.toString()); |
| | | }else { |
| | | StringBuilder stringBuilder = new StringBuilder(null==older.getLog()?"":older.getLog()); |
| | | stringBuilder.append(builder); |
| | | // 填报 |
| | | newer.setLog(stringBuilder.toString()); |
| | | // 拼接 |
| | | String time = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date()); |
| | | String userName = AuthUtil.getUser().getUserName(); |
| | | String phone = userClient.userInfoById(AuthUtil.getUserId()).getData().getPhone(); |
| | | StringBuilder builder = new StringBuilder(); |
| | | builder.append(time) |
| | | .append(",") |
| | | .append(fillName) |
| | | .append(",") |
| | | .append(userName) |
| | | .append(",") |
| | | .append(phone) |
| | | .append(";"); |
| | | // 判断是否存在 |
| | | if (null==newer.getGuid() || newer.getGuid().equals("")){ |
| | | // 填报 |
| | | newer.setLog(builder.toString()); |
| | | }else { |
| | | for (TbResStagCapDisc older : oldList) { |
| | | if (older.getGuid().equals(newer.getGuid())){ |
| | | StringBuilder stringBuilder = new StringBuilder(null==older.getLog()?"":older.getLog()); |
| | | stringBuilder.append(builder); |
| | | // 填报 |
| | | newer.setLog(stringBuilder.toString()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 新增或更新数据 |
| | | * @param oldList |
| | | * @param newList |
| | | * @return |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean addOrUpdate(List<TbResStagCapDisc> oldList, List<TbResStagCapDisc> newList) { |
| | | // 取旧数据和新提交数据差集--删除 |
| | | // 去除前一天已填报的人员手机号集合 |
| | | List<TbResStagCapDisc> removeList = oldList.stream().filter(vo -> !newList.stream().map(e -> |
| | | e.getGuid()).collect(Collectors.toList()).contains(vo.getGuid())).collect(Collectors.toList()); |
| | | // 取旧数据和新提交数据交集--更新 |
| | | List<TbResStagCapDisc> updateList = newList.stream().filter(vo -> oldList.stream().map(e -> |
| | | e.getGuid()).collect(Collectors.toList()).contains(vo.getGuid())).collect(Collectors.toList()); |
| | | // 取新数提交据和旧数据交集--新增 |
| | | List<TbResStagCapDisc> addList = newList.stream().filter(vo -> !oldList.stream().map(e -> |
| | | e.getGuid()).collect(Collectors.toList()).contains(vo.getGuid())).collect(Collectors.toList()); |
| | | boolean addFlag = true; |
| | | boolean updateFlag = true; |
| | | boolean removeFlag = true; |
| | | if (addList.size()>0){ |
| | | // 批量新增 |
| | | addFlag = saveBatch(addList); |
| | | // tbAttResBaseService.updateFinalState(addList.get(0).getResGuid(),addList.get(0).getCheckState()); |
| | | } |
| | | if (updateList.size()>0){ |
| | | // 批量更新 |
| | | addFlag = updateBatchById(updateList); |
| | | // tbAttResBaseService.updateFinalState(updateList.get(0).getResGuid(),updateList.get(0).getCheckState()); |
| | | } |
| | | if (removeList.size()>0){ |
| | | // 批量删除 |
| | | removeFlag = removeBatchByIds(removeList); |
| | | } |
| | | if (addFlag && updateFlag && removeFlag){ |
| | | return true; |
| | | } |
| | | // 返回 |
| | | return false; |
| | | } |
| | | } |