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.UnionApplyMapper;
|
import com.doumee.dao.business.dto.SaveUnionApplyDTO;
|
import com.doumee.dao.business.join.InsuranceApplyJoinMapper;
|
import com.doumee.dao.business.model.InsuranceApply;
|
import com.doumee.dao.business.model.Solutions;
|
import com.doumee.dao.business.model.UnionApply;
|
import com.doumee.service.business.UnionApplyService;
|
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 com.github.yulichang.wrapper.MPJLambdaWrapper;
|
import io.swagger.models.auth.In;
|
import org.apache.commons.lang3.StringUtils;
|
import org.apache.shiro.SecurityUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.util.CollectionUtils;
|
|
import java.math.BigDecimal;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Objects;
|
|
/**
|
* 合并投保单信息表Service实现
|
* @author 江蹄蹄
|
* @date 2024/03/12 11:34
|
*/
|
@Service
|
public class UnionApplyServiceImpl implements UnionApplyService {
|
|
@Autowired
|
private UnionApplyMapper unionApplyMapper;
|
|
@Autowired
|
private InsuranceApplyJoinMapper insuranceApplyJoinMapper;
|
|
@Override
|
public Integer create(UnionApply unionApply) {
|
unionApplyMapper.insert(unionApply);
|
return unionApply.getId();
|
}
|
|
@Override
|
public void deleteById(Integer id) {
|
unionApplyMapper.deleteById(id);
|
}
|
|
@Override
|
public void delete(UnionApply unionApply) {
|
UpdateWrapper<UnionApply> deleteWrapper = new UpdateWrapper<>(unionApply);
|
unionApplyMapper.delete(deleteWrapper);
|
}
|
|
@Override
|
public void deleteByIdInBatch(List<Integer> ids) {
|
if (CollectionUtils.isEmpty(ids)) {
|
return;
|
}
|
unionApplyMapper.deleteBatchIds(ids);
|
}
|
|
@Override
|
public void updateById(UnionApply unionApply) {
|
unionApplyMapper.updateById(unionApply);
|
}
|
|
@Override
|
public void updateByIdInBatch(List<UnionApply> unionApplys) {
|
if (CollectionUtils.isEmpty(unionApplys)) {
|
return;
|
}
|
for (UnionApply unionApply: unionApplys) {
|
this.updateById(unionApply);
|
}
|
}
|
|
@Override
|
public UnionApply findById(Integer id) {
|
return unionApplyMapper.selectById(id);
|
}
|
|
@Override
|
public UnionApply findOne(UnionApply unionApply) {
|
QueryWrapper<UnionApply> wrapper = new QueryWrapper<>(unionApply);
|
return unionApplyMapper.selectOne(wrapper);
|
}
|
|
@Override
|
public List<UnionApply> findList(UnionApply unionApply) {
|
QueryWrapper<UnionApply> wrapper = new QueryWrapper<>(unionApply);
|
return unionApplyMapper.selectList(wrapper);
|
}
|
|
@Override
|
public PageData<UnionApply> findPage(PageWrap<UnionApply> pageWrap) {
|
IPage<UnionApply> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
|
QueryWrapper<UnionApply> queryWrapper = new QueryWrapper<>();
|
Utils.MP.blankToNull(pageWrap.getModel());
|
if (pageWrap.getModel().getId() != null) {
|
queryWrapper.lambda().eq(UnionApply::getId, pageWrap.getModel().getId());
|
}
|
if (pageWrap.getModel().getCreator() != null) {
|
queryWrapper.lambda().eq(UnionApply::getCreator, pageWrap.getModel().getCreator());
|
}
|
if (pageWrap.getModel().getCreateDate() != null) {
|
queryWrapper.lambda().ge(UnionApply::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate()));
|
queryWrapper.lambda().le(UnionApply::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate()));
|
}
|
if (pageWrap.getModel().getEditor() != null) {
|
queryWrapper.lambda().eq(UnionApply::getEditor, pageWrap.getModel().getEditor());
|
}
|
if (pageWrap.getModel().getEditDate() != null) {
|
queryWrapper.lambda().ge(UnionApply::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate()));
|
queryWrapper.lambda().le(UnionApply::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate()));
|
}
|
if (pageWrap.getModel().getIsdeleted() != null) {
|
queryWrapper.lambda().eq(UnionApply::getIsdeleted, pageWrap.getModel().getIsdeleted());
|
}
|
if (pageWrap.getModel().getRemark() != null) {
|
queryWrapper.lambda().eq(UnionApply::getRemark, pageWrap.getModel().getRemark());
|
}
|
if (pageWrap.getModel().getSortnum() != null) {
|
queryWrapper.lambda().eq(UnionApply::getSortnum, pageWrap.getModel().getSortnum());
|
}
|
if (pageWrap.getModel().getCompanyId() != null) {
|
queryWrapper.lambda().eq(UnionApply::getCompanyId, pageWrap.getModel().getCompanyId());
|
}
|
if (pageWrap.getModel().getEndTime() != null) {
|
queryWrapper.lambda().ge(UnionApply::getEndTime, Utils.Date.getStart(pageWrap.getModel().getEndTime()));
|
queryWrapper.lambda().le(UnionApply::getEndTime, Utils.Date.getEnd(pageWrap.getModel().getEndTime()));
|
}
|
if (pageWrap.getModel().getStartTime() != null) {
|
queryWrapper.lambda().ge(UnionApply::getStartTime, Utils.Date.getStart(pageWrap.getModel().getStartTime()));
|
queryWrapper.lambda().le(UnionApply::getStartTime, Utils.Date.getEnd(pageWrap.getModel().getStartTime()));
|
}
|
if (pageWrap.getModel().getCheckDate() != null) {
|
queryWrapper.lambda().ge(UnionApply::getCheckDate, Utils.Date.getStart(pageWrap.getModel().getCheckDate()));
|
queryWrapper.lambda().le(UnionApply::getCheckDate, Utils.Date.getEnd(pageWrap.getModel().getCheckDate()));
|
}
|
if (pageWrap.getModel().getCheckInfo() != null) {
|
queryWrapper.lambda().eq(UnionApply::getCheckInfo, pageWrap.getModel().getCheckInfo());
|
}
|
if (pageWrap.getModel().getCheckUserId() != null) {
|
queryWrapper.lambda().eq(UnionApply::getCheckUserId, pageWrap.getModel().getCheckUserId());
|
}
|
if (pageWrap.getModel().getCode() != null) {
|
queryWrapper.lambda().eq(UnionApply::getCode, pageWrap.getModel().getCode());
|
}
|
if (pageWrap.getModel().getStatus() != null) {
|
queryWrapper.lambda().eq(UnionApply::getStatus, pageWrap.getModel().getStatus());
|
}
|
if (pageWrap.getModel().getCurrentFee() != null) {
|
queryWrapper.lambda().eq(UnionApply::getCurrentFee, pageWrap.getModel().getCurrentFee());
|
}
|
if (pageWrap.getModel().getFee() != null) {
|
queryWrapper.lambda().eq(UnionApply::getFee, pageWrap.getModel().getFee());
|
}
|
if (pageWrap.getModel().getSignApplyNo() != null) {
|
queryWrapper.lambda().eq(UnionApply::getSignApplyNo, pageWrap.getModel().getSignApplyNo());
|
}
|
for(PageWrap.SortData sortData: pageWrap.getSorts()) {
|
if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) {
|
queryWrapper.orderByDesc(sortData.getProperty());
|
} else {
|
queryWrapper.orderByAsc(sortData.getProperty());
|
}
|
}
|
return PageData.from(unionApplyMapper.selectPage(page, queryWrapper));
|
}
|
|
@Override
|
public long count(UnionApply unionApply) {
|
QueryWrapper<UnionApply> wrapper = new QueryWrapper<>(unionApply);
|
return unionApplyMapper.selectCount(wrapper);
|
}
|
|
|
@Override
|
public void merge(SaveUnionApplyDTO saveUnionApplyDTO){
|
LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
|
if(user.getType().equals(Constants.TWO)){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"非商户用户,无法进行该操作");
|
}
|
if(Objects.isNull(saveUnionApplyDTO)
|
|| Objects.isNull(saveUnionApplyDTO.getApplyIds())
|
|| Objects.isNull(saveUnionApplyDTO.getStartDate())
|
|| Objects.isNull(saveUnionApplyDTO.getEndDate())
|
){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST);
|
}
|
List<InsuranceApply> insuranceApplyList = insuranceApplyJoinMapper.selectJoinList(InsuranceApply.class,
|
new MPJLambdaWrapper<InsuranceApply>()
|
.selectAll(InsuranceApply.class)
|
.selectAs(InsuranceApply::getSolutionBaseId,Solutions::getBaseId)
|
.leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId)
|
.eq(InsuranceApply::getIsdeleted, Constants.ZERO)
|
.eq(InsuranceApply::getStatus,Constants.InsuranceApplyStatus.PLATFORM_CHECK_PASS.getKey())
|
.eq(Solutions::getBaseId,saveUnionApplyDTO.getBaseSolutionId())
|
.in(InsuranceApply::getId,saveUnionApplyDTO.getApplyIds())
|
.isNull(InsuranceApply::getUnionApplyId)
|
);
|
//查询数据是否存在未处于审批通过的数据
|
if(insuranceApplyList.size()!=saveUnionApplyDTO.getApplyIds().size()){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"存在数据已处理,请刷新重试");
|
}
|
|
UnionApply unionApply = new UnionApply();
|
unionApply.setCreateDate(new Date());
|
unionApply.setCreator(user.getId());
|
unionApply.setCompanyId(user.getCompanyId());
|
unionApply.setStartTime(saveUnionApplyDTO.getStartDate());
|
unionApply.setEndTime(saveUnionApplyDTO.getEndDate());
|
unionApply.setCheckDate(new Date());
|
unionApply.setStatus(Constants.UnionApplyStatus.UPLOAD.getKey());
|
unionApply.setCheckUserId(user.getId());
|
unionApply.setFee(insuranceApplyList.stream().map(i->i.getFee()).reduce(BigDecimal.ZERO,BigDecimal::add));
|
unionApply.setCurrentFee(BigDecimal.ZERO);
|
unionApplyMapper.insert(unionApply);
|
|
insuranceApplyJoinMapper.update(null,new UpdateWrapper<InsuranceApply>().lambda()
|
.set(InsuranceApply::getUnionApplyId,unionApply.getId())
|
.set(InsuranceApply::getCheckDate,new Date())
|
.set(InsuranceApply::getCheckUserId,user.getId())
|
.in(InsuranceApply::getId,saveUnionApplyDTO.getApplyIds()));
|
|
}
|
|
|
public void cancelMerge(Integer id){
|
LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
|
if(user.getType().equals(Constants.TWO)){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"非商户用户,无法进行该操作");
|
}
|
|
}
|
|
|
}
|