From 94b15dee8f8a9d181f14e99eaa620e52f197ee35 Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期二, 30 七月 2024 15:22:53 +0800
Subject: [PATCH] 提交一把
---
server/service/src/main/java/com/doumee/service/business/impl/InsuranceServiceImpl.java | 247 +++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 237 insertions(+), 10 deletions(-)
diff --git a/server/service/src/main/java/com/doumee/service/business/impl/InsuranceServiceImpl.java b/server/service/src/main/java/com/doumee/service/business/impl/InsuranceServiceImpl.java
index 50f3213..04808f9 100644
--- a/server/service/src/main/java/com/doumee/service/business/impl/InsuranceServiceImpl.java
+++ b/server/service/src/main/java/com/doumee/service/business/impl/InsuranceServiceImpl.java
@@ -1,20 +1,33 @@
package com.doumee.service.business.impl;
+import com.doumee.core.constants.ResponseStatus;
+import com.doumee.core.exception.BusinessException;
+import com.doumee.core.model.LoginUserInfo;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
+import com.doumee.core.utils.Constants;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.InsuranceMapper;
+import com.doumee.dao.business.WorktypeMapper;
import com.doumee.dao.business.model.Insurance;
+import com.doumee.dao.business.model.Solutions;
+import com.doumee.dao.business.model.Worktype;
+import com.doumee.dao.system.model.SystemUser;
import com.doumee.service.business.InsuranceService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shiro.SecurityUtils;
+import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
-import java.util.List;
+import java.util.*;
+import java.util.stream.Collectors;
/**
* 淇濋櫓鍏徃淇℃伅琛⊿ervice瀹炵幇
@@ -26,22 +39,139 @@
@Autowired
private InsuranceMapper insuranceMapper;
+ @Autowired
+ private WorktypeMapper worktypeMapper;
@Override
+ @Transactional
public Integer create(Insurance insurance) {
- insuranceMapper.insert(insurance);
+
+ LoginUserInfo user= (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
+ initCreateParam(insurance);//宸ョ鏁版嵁鏈夋晥鎬ф楠岋紝鍘婚櫎绌虹櫧琛屾暟鎹�
+
+ if(insuranceMapper.selectCount(new QueryWrapper<Insurance>().lambda().eq(Insurance::getName,insurance.getName())
+ .eq(Insurance::getIsdeleted,Constants.ZERO)
+ .eq(Insurance::getDataType,Constants.ZERO)
+ )>Constants.ZERO){
+ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"淇濋櫓鍏徃鍚嶇О宸插瓨鍦�");
+ }
+
+ insurance.setIsdeleted(Constants.ZERO);
+ insurance.setCreator(user.getId());
+ insurance.setCreateDate(new Date());
+ insurance.setVersion(UUID.randomUUID().toString());//鐗堟湰鍙�
+ insurance.setDataType(Constants.ZERO);
+ insurance.setStatus(Constants.ZERO);
+ insuranceMapper.insert(insurance);//鍩虹鐗堟湰
+
+ //濡傛灉鏈夊伐绉嶏紝鍒欎骇鐢熶竴涓柊鐨勬湁鏁堝巻鍙茬増鏈� ~
+ Insurance newModel = new Insurance();
+ BeanUtils.copyProperties(insurance,newModel);
+ newModel.setId(null);
+ newModel.setBaseId(insurance.getId());
+ newModel.setDataType(Constants.TWO);
+ insuranceMapper.insert(newModel);
+
+ dealWorkTypeData(insurance,newModel,insurance.getWorktypeList(),true);
+
return insurance.getId();
+ }
+ private void dealWorkTypeData(Insurance insurance, Insurance newModel, List<Worktype> worktypeList,boolean isNew) {
+ int num=0;
+ List<String> workTypeName = worktypeList.stream().map(m->m.getName()).collect(Collectors.toList());
+ Set<String> set = new HashSet<>(workTypeName);
+ if(workTypeName.size() != set.size()){
+ throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(),"瀵逛笉璧凤紝宸ョ褰曞叆鏁版嵁瀛樺湪鐩稿悓鏁版嵁锛�");
+ }
+ for(Worktype w : worktypeList) {
+ if(!isNew){
+ //鏌ヨ淇濋櫓鍏徃涓嬫槸鍚﹀凡瀛樺湪璇ュ伐绉�
+ if(worktypeMapper.selectCount(new QueryWrapper<Worktype>().lambda().eq(Worktype::getInsuranceId,insurance.getId())
+ .eq(Worktype::getIsdeleted,Constants.ZERO)
+ .eq(Worktype::getDataType,Constants.ZERO)
+ .eq(Worktype::getName,w.getName())
+ )>Constants.ZERO){
+ throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"褰撳墠淇濋櫓鍏徃涓嬪瓨鍦ㄣ��"+w.getName()+"銆戣宸ョ淇℃伅");
+ }
+ }
+ //鍩虹鐗堟湰
+ w.setInsuranceId(insurance.getId());
+ w.setIsdeleted(Constants.ZERO);
+ w.setCreator(newModel.getCreator());
+ w.setCreateDate(insurance.getCreateDate());
+ w.setDataType(insurance.getDataType());
+ w.setStatus(Constants.ZERO);
+ w.setVersion(insurance.getVersion());
+ w.setSortnum(num++);
+ worktypeMapper.insert(w);
+
+
+ //鍘嗗彶鐗堟湰鐨勫伐绉嶄俊鎭�
+ Worktype newType = new Worktype();
+ BeanUtils.copyProperties(w, newType);
+ newType.setInsuranceId(newModel.getId());
+ newType.setBaseId(w.getId());
+ newType.setDataType(Constants.TWO);
+ newType.setVersion(newModel.getVersion());
+ w.setSortnum(num++);
+ worktypeMapper.insert(newType);
+ }
+ }
+
+ private void initCreateParam(Insurance insurance) {
+ if(StringUtils.isBlank(insurance.getName())){
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝璇疯緭鍏ヤ繚闄╁叕鍙稿悕绉帮紒");
+ }
+ List<Worktype> worktypeList = new ArrayList<>();
+ if(insurance.getWorktypeList()!=null && insurance.getWorktypeList().size()>0){
+ for(Worktype w : insurance.getWorktypeList()){
+ if(StringUtils.isNotBlank(w.getName())){
+ worktypeList.add(w);
+ }
+ }
+ }
+ if(worktypeList.size()==0){
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝宸ョ涓嶈兘涓虹┖锛�");
+ }
+ insurance.setWorktypeList(worktypeList);
}
@Override
public void deleteById(Integer id) {
- insuranceMapper.deleteById(id);
+ LoginUserInfo user= (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
+ Insurance model = findById(id);
+ if(model == null || !Constants.equalsInteger(model.getDataType(),Constants.ZERO)){
+ throw new BusinessException(ResponseStatus.DATA_EMPTY );
+ }
+ Insurance update = new Insurance();
+ update.setIsdeleted(Constants.ZERO);
+ update.setEditDate(new Date());
+ update.setEditor(user.getId());
+ update.setId(id);
+ insuranceMapper.updateById(update);
+
+ //閫昏緫鍒犻櫎鎵�鏈夊伐绉嶆暟鎹�
+ worktypeMapper.update(null,new UpdateWrapper<Worktype>()
+ .lambda()
+ .eq(Worktype::getInsuranceId,id)
+ .eq(Worktype::getIsdeleted,Constants.ZERO)
+ .set(Worktype::getIsdeleted,Constants.ONE)
+ );
}
@Override
public void delete(Insurance insurance) {
- UpdateWrapper<Insurance> deleteWrapper = new UpdateWrapper<>(insurance);
- insuranceMapper.delete(deleteWrapper);
+ LoginUserInfo user= (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
+ Insurance model = findById(insurance.getId());
+ if(model == null || !Constants.equalsInteger(model.getDataType(),Constants.ZERO)){
+ throw new BusinessException(ResponseStatus.DATA_EMPTY );
+ }
+ Insurance update = new Insurance();
+ update.setIsdeleted(Constants.ZERO);
+ update.setEditDate(new Date());
+ update.setId(insurance.getId());
+ update.setEditor(user.getId());
+ insuranceMapper.updateById(update);
}
@Override
@@ -54,7 +184,90 @@
@Override
public void updateById(Insurance insurance) {
- insuranceMapper.updateById(insurance);
+ Insurance model = findById(insurance.getId());
+ if(model == null || !Constants.equalsInteger(model.getIsdeleted(),Constants.ZERO)
+ || !Constants.equalsInteger(model.getDataType(),Constants.ZERO)){
+ throw new BusinessException(ResponseStatus.DATA_EMPTY );
+ }
+ //鏁版嵁鏈夋晥鎬ф牎楠�
+ initCreateParam(insurance);
+ if(insuranceMapper.selectCount(new QueryWrapper<Insurance>().lambda().eq(Insurance::getName,insurance.getName())
+ .eq(Insurance::getIsdeleted,Constants.ZERO)
+ .eq(Insurance::getDataType,Constants.ZERO)
+ .ne(Insurance::getId,insurance.getId())
+ )>Constants.ZERO){
+ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"淇濋櫓鍏徃鍚嶇О宸插瓨鍦�");
+ }
+
+ LoginUserInfo user= (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
+ Insurance updateModel = new Insurance();
+ updateModel.setEditor(user.getId());
+ updateModel.setName(insurance.getName());
+ updateModel.setId(model.getId());
+ updateModel.setVersion(UUID.randomUUID().toString());
+ updateModel.setEditDate(new Date());
+ updateModel.setRemark(insurance.getRemark());
+ updateModel.setSortnum(insurance.getSortnum());
+ insuranceMapper.updateById(updateModel);
+
+ //濡傛灉淇敼锛屽垯浜х敓涓�涓柊鐨勫巻鍙茬増鏈� ~
+ Insurance newModel = new Insurance();
+ BeanUtils.copyProperties(model,newModel);
+ newModel.setId(null);
+ newModel.setVersion(updateModel.getVersion());
+ newModel.setCreateDate(new Date());
+ newModel.setName(updateModel.getName());
+ newModel.setBaseId(insurance.getId());
+ newModel.setDataType(Constants.TWO);
+ insuranceMapper.insert(newModel);
+
+ //鍒犻櫎鎵�鏈夊伐绉嶆暟鎹�
+ worktypeMapper.delete(new UpdateWrapper<Worktype>()
+ .lambda()
+ .eq(Worktype::getInsuranceId,insurance.getId())
+ );
+ insuranceMapper.update(null,new UpdateWrapper<Insurance>()
+ .lambda()
+ .eq(Insurance::getBaseId,insurance.getId())
+ .eq(Insurance::getDataType,Constants.TWO)
+ .ne(Insurance::getId,newModel.getId())
+ .set(Insurance::getDataType,Constants.ONE)
+ );
+ worktypeMapper.update(null,new UpdateWrapper<Worktype>()
+ .lambda()
+ .eq(Worktype::getBaseId,insurance.getId())
+ .eq(Worktype::getDataType,Constants.TWO)
+ .set(Worktype::getDataType,Constants.ONE)
+ );
+
+ //澶勭悊宸ヤ綔淇℃伅锛屾柊澧炴渶鏂扮殑锛屽悓鏃朵骇鐢熷巻鍙茬増鏈�
+ dealWorkTypeData(updateModel,newModel,insurance.getWorktypeList(),false);
+ }
+
+ @Override
+ public void updateStatus(Insurance insurance){
+ if(insurance.getId() == null || insurance.getStatus()==null || insurance.getStatus()<0||insurance.getStatus()>1){
+ throw new BusinessException(ResponseStatus.BAD_REQUEST );
+ }
+ Insurance model = findById(insurance.getId());
+ if(model == null || !Constants.equalsInteger(model.getIsdeleted(),Constants.ZERO)
+ || !Constants.equalsInteger(model.getDataType(),Constants.ZERO)){
+ throw new BusinessException(ResponseStatus.DATA_EMPTY );
+ }
+ if(Constants.equalsInteger(model.getStatus(),insurance.getStatus())){
+ //濡傛灉鐘舵�佷笉鍙戠敓鏀瑰彉锛岀洿鎺ヨ繑鍥�
+ return;
+ }
+ LoginUserInfo user= (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
+ //鍚屾椂鏇存柊鍩鸿〃鍜屽巻鍙茬増鏈墍鏈夋暟鎹姸鎬�
+ insuranceMapper.update(null,new UpdateWrapper<Insurance>()
+ .lambda()
+ .and(m -> m.eq(Insurance::getId,model.getId()).or().eq(Insurance::getBaseId,model.getId()))
+ .eq(Insurance::getIsdeleted,Constants.ZERO)
+ .set(Insurance::getEditDate,new Date())
+ .set(Insurance::getEditor,user.getId())
+ .set(Insurance::getStatus,insurance.getStatus())
+ );
}
@Override
@@ -69,7 +282,16 @@
@Override
public Insurance findById(Integer id) {
- return insuranceMapper.selectById(id);
+ Insurance model = insuranceMapper.selectById(id);
+ if(model == null || !Constants.equalsInteger(model.getIsdeleted(),Constants.ZERO)){
+ throw new BusinessException(ResponseStatus.DATA_EMPTY );
+ }
+ List<Worktype> worktypeList = worktypeMapper.selectList(new QueryWrapper<Worktype>().lambda()
+ .eq(Worktype::getInsuranceId,id)
+ .eq(Worktype::getIsdeleted,Constants.ZERO)
+ .orderByAsc(Worktype::getSortnum));
+ model.setWorktypeList(worktypeList);
+ return model;
}
@Override
@@ -80,6 +302,7 @@
@Override
public List<Insurance> findList(Insurance insurance) {
+ insurance.setIsdeleted(Constants.ZERO);
QueryWrapper<Insurance> wrapper = new QueryWrapper<>(insurance);
return insuranceMapper.selectList(wrapper);
}
@@ -89,6 +312,8 @@
IPage<Insurance> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
QueryWrapper<Insurance> queryWrapper = new QueryWrapper<>();
Utils.MP.blankToNull(pageWrap.getModel());
+ pageWrap.getModel().setDataType(Constants.ZERO);//鍙�夋嫨鍩鸿〃鏁版嵁
+ pageWrap.getModel().setIsdeleted(Constants.ZERO);
if (pageWrap.getModel().getId() != null) {
queryWrapper.lambda().eq(Insurance::getId, pageWrap.getModel().getId());
}
@@ -110,7 +335,7 @@
queryWrapper.lambda().eq(Insurance::getIsdeleted, pageWrap.getModel().getIsdeleted());
}
if (pageWrap.getModel().getName() != null) {
- queryWrapper.lambda().eq(Insurance::getName, pageWrap.getModel().getName());
+ queryWrapper.lambda().like(Insurance::getName, pageWrap.getModel().getName());
}
if (pageWrap.getModel().getRemark() != null) {
queryWrapper.lambda().eq(Insurance::getRemark, pageWrap.getModel().getRemark());
@@ -130,13 +355,15 @@
if (pageWrap.getModel().getBaseId() != null) {
queryWrapper.lambda().eq(Insurance::getBaseId, pageWrap.getModel().getBaseId());
}
- for(PageWrap.SortData sortData: pageWrap.getSorts()) {
+ /* for(PageWrap.SortData sortData: pageWrap.getSorts()) {
if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) {
queryWrapper.orderByDesc(sortData.getProperty());
} else {
queryWrapper.orderByAsc(sortData.getProperty());
}
- }
+
+ }*/
+ queryWrapper.lambda().orderByAsc(Insurance::getSortnum);
return PageData.from(insuranceMapper.selectPage(page, queryWrapper));
}
--
Gitblit v1.9.3