| | |
| | | package cn.gistack.sm.sjztmd.service.impl; |
| | | |
| | | import cn.gistack.sm.sjztmd.entity.TbAttResWaterBlock; |
| | | import cn.gistack.sm.sjztmd.entity.TbAttResWaterBlock; |
| | | import cn.gistack.sm.sjztmd.mapper.TbAttResWaterBlockMapper; |
| | | import cn.gistack.sm.sjztmd.service.ITbAttResWaterBlockService; |
| | | import cn.gistack.system.user.feign.IUserClient; |
| | |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @ClassName TbAttResWaterBlockServiceImpl |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public TbAttResWaterBlock getDetailByGuid(String guid) { |
| | | public List<TbAttResWaterBlock> getDetailByGuid(String guid) { |
| | | return baseMapper.getDetailByResGuid(guid); |
| | | } |
| | | |
| | | /** |
| | | * 编辑 |
| | | * @param tbAttResWaterBlock |
| | | * @param newList |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean updateByGuid(TbAttResWaterBlock tbAttResWaterBlock) { |
| | | public boolean updateByGuid(List<TbAttResWaterBlock> newList) { |
| | | // 查询是否存在 |
| | | TbAttResWaterBlock detail = baseMapper.getDetailByResGuid(tbAttResWaterBlock.getResGuid()); |
| | | List<TbAttResWaterBlock> oldList = baseMapper.getDetailByResGuid(newList.get(0).getResGuid()); |
| | | // 更新日志 |
| | | setUpdateLog(detail,tbAttResWaterBlock); |
| | | // 修改 |
| | | int i = addOrUpdateByGuid(detail,tbAttResWaterBlock); |
| | | if (i>0){ |
| | | setUpdateLog(oldList,newList); |
| | | // 创建或更新数据 |
| | | boolean flag = addOrUpdate(oldList,newList); |
| | | // 返回 |
| | | return flag; |
| | | } |
| | | |
| | | /** |
| | | * 新增或更新数据 |
| | | * @param oldList |
| | | * @param newList |
| | | * @return |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean addOrUpdate(List<TbAttResWaterBlock> oldList,List<TbAttResWaterBlock> newList) { |
| | | // 取旧数据和新提交数据差集--删除 |
| | | // 去除前一天已填报的人员手机号集合 |
| | | List<TbAttResWaterBlock> removeList = oldList.stream().filter(vo -> !newList.stream().map(e -> |
| | | e.getGuid()).collect(Collectors.toList()).contains(vo.getGuid())).collect(Collectors.toList()); |
| | | // 取旧数据和新提交数据交集--更新 |
| | | List<TbAttResWaterBlock> updateList = newList.stream().filter(vo -> oldList.stream().map(e -> |
| | | e.getGuid()).collect(Collectors.toList()).contains(vo.getGuid())).collect(Collectors.toList()); |
| | | // 取新数提交据和旧数据交集--新增 |
| | | List<TbAttResWaterBlock> 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); |
| | | } |
| | | if (updateList.size()>0){ |
| | | // 批量更新 |
| | | addFlag = updateBatchById(updateList); |
| | | } |
| | | if (removeList.size()>0){ |
| | | // 批量删除 |
| | | removeFlag = removeBatchByIds(removeList); |
| | | } |
| | | if (addFlag && updateFlag && removeFlag){ |
| | | return true; |
| | | } |
| | | // 返回 |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 审核 |
| | | * @param tbAttResWaterBlock |
| | | * @param newList |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean auditByGuid(TbAttResWaterBlock tbAttResWaterBlock) { |
| | | public boolean auditByGuid(List<TbAttResWaterBlock> newList) { |
| | | // 查询是否存在 |
| | | TbAttResWaterBlock detail = baseMapper.getDetailByResGuid(tbAttResWaterBlock.getResGuid()); |
| | | List<TbAttResWaterBlock> oldList = baseMapper.getDetailByResGuid(newList.get(0).getResGuid()); |
| | | // 更新操作日志 |
| | | setUpdateLog(detail,tbAttResWaterBlock); |
| | | setUpdateLog(oldList,newList); |
| | | // 更新审核日志 |
| | | setUpdateCheckLog(detail,tbAttResWaterBlock); |
| | | if (null!=detail){ |
| | | tbAttResWaterBlock.setGuid(detail.getGuid()); |
| | | } |
| | | // 驳回情况下将状态修改回0即已填写未提交状态 |
| | | if (tbAttResWaterBlock.getCheckState()==3){ |
| | | tbAttResWaterBlock.setCheckState(0); |
| | | } |
| | | setUpdateCheckLog(oldList,newList); |
| | | // 更新数据 |
| | | int i = baseMapper.updateById(tbAttResWaterBlock); |
| | | if (i>0){ |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 更新 |
| | | * @param tbAttResWaterBlock |
| | | * @return |
| | | */ |
| | | private int addOrUpdateByGuid(TbAttResWaterBlock oldAbAttResBase,TbAttResWaterBlock tbAttResWaterBlock){ |
| | | int i = 0; |
| | | if (null!=oldAbAttResBase){ |
| | | tbAttResWaterBlock.setGuid(oldAbAttResBase.getGuid()); |
| | | // 更新 |
| | | i = baseMapper.updateById(tbAttResWaterBlock); |
| | | }else { |
| | | tbAttResWaterBlock.setCreateTime(new Date()); |
| | | i = baseMapper.insert(tbAttResWaterBlock); |
| | | } |
| | | boolean batch = updateBatchById(newList); |
| | | // 返回 |
| | | return i; |
| | | return batch; |
| | | } |
| | | |
| | | /** |
| | | * @param oldAbAttResBase |
| | | * @param newTbAttResWaterBlock |
| | | * @param oldList |
| | | * @param newList |
| | | * 更新审核记录 |
| | | */ |
| | | private void setUpdateCheckLog(TbAttResWaterBlock oldAbAttResBase,TbAttResWaterBlock newTbAttResWaterBlock) { |
| | | String fillName = ""; |
| | | if (newTbAttResWaterBlock.getCheckState()==2){ |
| | | fillName = "审核"; |
| | | } |
| | | if (newTbAttResWaterBlock.getCheckState()==3){ |
| | | fillName = "退回" + (null==newTbAttResWaterBlock.getCheckLog()?"":":" + newTbAttResWaterBlock.getCheckLog()); |
| | | } |
| | | private void setUpdateCheckLog(List<TbAttResWaterBlock> oldList,List<TbAttResWaterBlock> newList) { |
| | | // 遍历 |
| | | for (TbAttResWaterBlock newTbAttResWaterBlock : newList) { |
| | | String fillName = ""; |
| | | if (newTbAttResWaterBlock.getCheckState() == 2) { |
| | | fillName = "审核"; |
| | | } |
| | | if (newTbAttResWaterBlock.getCheckState() == 3) { |
| | | fillName = "退回" + (null == newTbAttResWaterBlock.getCheckLog() ? "" : ":" + newTbAttResWaterBlock.getCheckLog()); |
| | | for (TbAttResWaterBlock tbAttResWaterBlock : oldList) { |
| | | if (tbAttResWaterBlock.getGuid().equals(newTbAttResWaterBlock.getGuid())){ |
| | | // 退回时进行设置状态为填写中 |
| | | newTbAttResWaterBlock.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==oldAbAttResBase){ |
| | | // 填报 |
| | | newTbAttResWaterBlock.setCheckLog(builder.toString()); |
| | | }else { |
| | | StringBuilder stringBuilder = new StringBuilder(null==oldAbAttResBase.getCheckLog()?"":oldAbAttResBase.getCheckLog()); |
| | | stringBuilder.append(builder); |
| | | // 填报 |
| | | newTbAttResWaterBlock.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==newTbAttResWaterBlock.getGuid() || newTbAttResWaterBlock.getGuid().equals("")){ |
| | | // 填报 |
| | | newTbAttResWaterBlock.setCheckLog(builder.toString()); |
| | | } else { |
| | | for (TbAttResWaterBlock tbAttResWaterBlock : oldList) { |
| | | if (tbAttResWaterBlock.getGuid().equals(newTbAttResWaterBlock.getGuid())){ |
| | | StringBuilder stringBuilder = new StringBuilder(null == tbAttResWaterBlock.getCheckLog() ? "" : tbAttResWaterBlock.getCheckLog()); |
| | | stringBuilder.append(builder); |
| | | // 填报 |
| | | newTbAttResWaterBlock.setCheckLog(stringBuilder.toString()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @param oldAbAttResBase |
| | | * @param newTbAttResWaterBlock |
| | | * @param oldList |
| | | * @param newList |
| | | * 更新操作记录 |
| | | */ |
| | | private void setUpdateLog(TbAttResWaterBlock oldAbAttResBase,TbAttResWaterBlock newTbAttResWaterBlock) { |
| | | String fillName = ""; |
| | | if (newTbAttResWaterBlock.getCheckState()==0){ |
| | | fillName = "编辑"; |
| | | } |
| | | if (newTbAttResWaterBlock.getCheckState()==1){ |
| | | fillName = "提交"; |
| | | } |
| | | if (newTbAttResWaterBlock.getCheckState()==2){ |
| | | fillName = "审核"; |
| | | } |
| | | if (newTbAttResWaterBlock.getCheckState()==3){ |
| | | fillName = "退回" + (null==newTbAttResWaterBlock.getCheckLog()?"":":" + newTbAttResWaterBlock.getCheckLog()); |
| | | } |
| | | if (newTbAttResWaterBlock.getCheckState()==4){ |
| | | fillName = "编辑"; |
| | | newTbAttResWaterBlock.setCheckState(oldAbAttResBase.getCheckState()); |
| | | } |
| | | private void setUpdateLog(List<TbAttResWaterBlock> oldList,List<TbAttResWaterBlock> newList) { |
| | | // 遍历 |
| | | for (TbAttResWaterBlock newTbAttResWaterBlock : newList){ |
| | | String fillName = ""; |
| | | if (newTbAttResWaterBlock.getCheckState()==0){ |
| | | fillName = "编辑"; |
| | | } |
| | | if (newTbAttResWaterBlock.getCheckState()==1){ |
| | | fillName = "提交"; |
| | | } |
| | | if (newTbAttResWaterBlock.getCheckState()==2){ |
| | | fillName = "审核"; |
| | | } |
| | | if (newTbAttResWaterBlock.getCheckState()==3){ |
| | | fillName = "退回" + (null==newTbAttResWaterBlock.getCheckLog()?"":":" + newTbAttResWaterBlock.getCheckLog()); |
| | | } |
| | | // 管理员编辑 |
| | | if (newTbAttResWaterBlock.getCheckState()==4){ |
| | | fillName = "编辑"; |
| | | // 找到相关的 guid 数据 |
| | | for (TbAttResWaterBlock tbAttResWaterBlock : oldList) { |
| | | if (tbAttResWaterBlock.getGuid().equals(newTbAttResWaterBlock.getGuid())){ |
| | | newTbAttResWaterBlock.setCheckState(tbAttResWaterBlock.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==oldAbAttResBase){ |
| | | // 填报 |
| | | newTbAttResWaterBlock.setLog(builder.toString()); |
| | | }else { |
| | | StringBuilder stringBuilder = new StringBuilder(null==oldAbAttResBase.getLog()?"":oldAbAttResBase.getLog()); |
| | | stringBuilder.append(builder); |
| | | // 填报 |
| | | newTbAttResWaterBlock.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==newTbAttResWaterBlock.getGuid() || newTbAttResWaterBlock.getGuid().equals("")){ |
| | | // 填报 |
| | | newTbAttResWaterBlock.setLog(builder.toString()); |
| | | }else { |
| | | for (TbAttResWaterBlock tbAttResWaterBlock : oldList) { |
| | | if (tbAttResWaterBlock.getGuid().equals(newTbAttResWaterBlock.getGuid())){ |
| | | StringBuilder stringBuilder = new StringBuilder(null==tbAttResWaterBlock.getLog()?"":tbAttResWaterBlock.getLog()); |
| | | stringBuilder.append(builder); |
| | | // 填报 |
| | | newTbAttResWaterBlock.setLog(stringBuilder.toString()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |