支出合同功能开发

This commit is contained in:
梁琦涛
2021-09-07 18:48:12 +08:00
parent 039b1d58c2
commit 2a1867cfa9
6 changed files with 305 additions and 36 deletions
@@ -20,14 +20,10 @@ import com.jero.contract.entity.PayIncomeContract;
import com.jero.contract.entity.PayIncomeContractAssociated;
import com.jero.contract.entity.PayIncomeContractAudit;
import com.jero.contract.entity.PayIncomeContractInstallment;
import com.jero.contract.service.IPayIncomeContractAssociatedService;
import com.jero.contract.service.IPayIncomeContractAuditService;
import com.jero.contract.service.IPayIncomeContractInstallmentService;
import com.jero.contract.service.IPayIncomeContractService;
import com.jero.contract.vo.*;
import com.jero.project.service.IPayCommonProjectService;
import com.jero.project.service.IPayWorkingGroupService;
import com.jero.project.service.IPayWorkingGroupSubItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
@@ -41,7 +37,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
@@ -1,24 +1,20 @@
package com.jero.contract.controller;
import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jero.common.api.vo.Result;
import com.jero.common.aspect.annotation.AutoLog;
import com.jero.common.system.base.controller.JeroController;
import com.jero.common.system.query.QueryGenerator;
import com.jero.contract.entity.PayIncomeContract;
import com.jero.contract.entity.PaySpendingContract;
import com.jero.contract.service.IPaySpendingContractService;
import com.jero.contract.vo.PayIncomeContractOutput;
import com.jero.contract.vo.PaySpendingContractInput;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@@ -57,49 +53,49 @@ public class PaySpendingContractController extends JeroController<PaySpendingCon
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
@RequestParam(name="startTime",required = false) String startTime,
@RequestParam(name="endTime",required = false) String endTime) {
@RequestParam(name="endTime",required = false) String endTime,
HttpServletRequest req) {
if(!StringUtils.isBlank(paySpendingContract.getContractNum()) && paySpendingContract.getContractNum().length() > 50){
return Result.error("合同编号长度不能大于50个字符!");
}
if(!StringUtils.isBlank(paySpendingContract.getContractName()) && paySpendingContract.getContractName().length() > 50){
return Result.error("合同名称长度不能大于50个字符!");
}
// Page<PaySpendingContractOutput> page = new Page<>(pageNo, pageSize);
// IPage<PaySpendingContract> pageList = payIncomeContractService.queryPageList(page, payIncomeContract,chargeStatus,projectName,startTime,endTime);
// if(!CollectionUtils.isEmpty(pageList.getRecords())){
// List<PayIncomeContractOutput> list = pageList.getRecords();
// list.forEach(p->{
//
// });
// }
return Result.OK(null);
LambdaQueryWrapper<PaySpendingContract> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(PaySpendingContract::getContractNum,paySpendingContract.getContractNum());
queryWrapper.eq(PaySpendingContract::getContractName,paySpendingContract.getContractName());
queryWrapper.ge(PaySpendingContract::getCreateTime,startTime);
queryWrapper.le(PaySpendingContract::getCreateTime,endTime);
Page<PaySpendingContract> page = new Page<>(pageNo, pageSize);
IPage<PaySpendingContract> pageList = paySpendingContractService.page(page, queryWrapper);
return Result.OK(pageList);
}
/**
* 添加
*
* @param paySpendingContract
* @param input 支出合同
* @return
*/
@AutoLog(value = "支出合同-添加")
@ApiOperation(value="支出合同-添加", notes="支出合同-添加")
@PostMapping(value = "/add")
public Result<?> add(@RequestBody PaySpendingContract paySpendingContract) {
paySpendingContractService.save(paySpendingContract);
return Result.OK("添加成功!");
public Result<?> add(@RequestBody PaySpendingContractInput input) {
PaySpendingContract paySpendingContract = paySpendingContractService.addPaySpendingContractInput(input);
return Result.OK("添加成功!",paySpendingContract);
}
/**
* 编辑
*
* @param paySpendingContract
* @param input 支出合同
* @return
*/
@AutoLog(value = "支出合同-编辑")
@ApiOperation(value="支出合同-编辑", notes="支出合同-编辑")
@PostMapping(value = "/edit")
public Result<?> edit(@RequestBody PaySpendingContract paySpendingContract) {
paySpendingContractService.updateById(paySpendingContract);
public Result<?> edit(@RequestBody PaySpendingContractInput input) {
paySpendingContractService.editPayIncomeContractInput(input);
return Result.OK("编辑成功!");
}
@@ -112,8 +108,11 @@ public class PaySpendingContractController extends JeroController<PaySpendingCon
@AutoLog(value = "支出合同-通过id删除")
@ApiOperation(value="支出合同-通过id删除", notes="支出合同-通过id删除")
@GetMapping(value = "/delete")
public Result<?> delete(@RequestParam(name="id",required=true) String id) {
paySpendingContractService.removeById(id);
public Result<?> delete(@RequestParam(name="id") String id) {
if(StringUtils.isBlank(id)){
return Result.error("id不能为空!");
}
paySpendingContractService.deletePaySpendingContractInputById(id);
return Result.OK("删除成功!");
}
@@ -126,8 +125,17 @@ public class PaySpendingContractController extends JeroController<PaySpendingCon
@AutoLog(value = "支出合同-批量删除")
@ApiOperation(value="支出合同-批量删除", notes="支出合同-批量删除")
@GetMapping(value = "/deleteBatch")
public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
this.paySpendingContractService.removeByIds(Arrays.asList(ids.split(",")));
public Result<?> deleteBatch(@RequestParam(name="ids") String ids) {
if(StringUtils.isBlank(ids)){
return Result.error("id不能为空!");
}
String[] s = ids.split(",");
for (String s1 : s) {
if(StringUtils.isBlank(s1)){
return Result.error("id不能为空!");
}
}
paySpendingContractService.deleteSpendingContractInputByIds(Arrays.asList(ids.split(",")));
return Result.OK("批量删除成功!");
}
@@ -136,10 +136,6 @@ public class PaySpendingContract implements Serializable {
@Excel(name = "打包年份", width = 15)
@ApiModelProperty(value = "打包年份")
private String packYear;
/**合同状态(1:草稿,2:已通过,3:未通过,4:已归档)*/
@Excel(name = "合同状态(1:草稿,2:已通过,3:未通过,4:已归档)", width = 15)
@ApiModelProperty(value = "合同状态(1:草稿,2:已通过,3:未通过,4:已归档)")
private Integer contractStatus;
/**创建人*/
@ApiModelProperty(value = "创建人")
private String createBy;
@@ -2,6 +2,9 @@ package com.jero.contract.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.jero.contract.entity.PaySpendingContract;
import com.jero.contract.vo.PaySpendingContractInput;
import java.util.List;
/**
* @Description: pay_spending_contract
@@ -11,4 +14,40 @@ import com.jero.contract.entity.PaySpendingContract;
*/
public interface IPaySpendingContractService extends IService<PaySpendingContract> {
/**
* @Description 添加
* @Author lqt
* @Date 2021/9/7
* @Param
* @Return
* @Exception
*/
PaySpendingContract addPaySpendingContractInput(PaySpendingContractInput input);
/**
* @Description 编辑
* @Author lqt
* @Date 2021/9/7
* @Param
* @Return
* @Exception
*/
void editPayIncomeContractInput(PaySpendingContractInput input);
/**
* @Description 通过id删除
* @Author lqt
* @Date 2021/9/7
* @Param
* @Return
* @Exception
*/
void deletePaySpendingContractInputById(String id);
/**
* @Description 批量删除
* @Author lqt
* @Date 2021/9/7
* @Param
* @Return
* @Exception
*/
void deleteSpendingContractInputByIds(List<String> ids);
}
@@ -1,18 +1,226 @@
package com.jero.contract.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jero.common.exception.JeroBootException;
import com.jero.common.util.ValidUtil;
import com.jero.contract.common.PayIncomeContractCommon;
import com.jero.contract.entity.PayIncomeContract;
import com.jero.contract.entity.PayIncomeContractInstallment;
import com.jero.contract.entity.PaySpendingContract;
import com.jero.contract.entity.PaySpendingContractInstallment;
import com.jero.contract.mapper.PaySpendingContractMapper;
import com.jero.contract.service.IPaySpendingContractInstallmentService;
import com.jero.contract.service.IPaySpendingContractService;
import com.jero.contract.vo.PaySpendingContractInput;
import com.jero.modules.system.entity.SysUser;
import com.jero.modules.system.service.ISysUserService;
import com.jero.temporary.entity.PayCompanyManagementTemporary;
import com.jero.temporary.entity.PayContactsManagementTemporary;
import com.jero.temporary.service.IPayCompanyManagementTemporaryService;
import com.jero.temporary.service.IPayContactsManagementTemporaryService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* @Description: pay_spending_contract
* @Author: jeecg-boot
* @Date: 2021-09-07
* @Version: V1.0
*/
@Slf4j
@Service
public class PaySpendingContractServiceImpl extends ServiceImpl<PaySpendingContractMapper, PaySpendingContract> implements IPaySpendingContractService {
@Autowired
private IPaySpendingContractInstallmentService paySpendingContractInstallmentService;
@Autowired
private IPaySpendingContractService paySpendingContractService;
@Autowired
private IPayCompanyManagementTemporaryService payCompanyManagementTemporaryService;
@Autowired
private IPayContactsManagementTemporaryService payContactsManagementTemporaryService;
@Autowired
private ISysUserService sysUserService;
@Override
public PaySpendingContract addPaySpendingContractInput(PaySpendingContractInput input) {
if(Objects.isNull(input)){
throw new JeroBootException("支出合同信息不能为空!");
}
PaySpendingContract paySpendingContract = input.getContract();
if(Objects.isNull(paySpendingContract)){
throw new JeroBootException("支出合同信息不能为空!");
}
StringBuilder msgPayIncomeContract = ValidUtil.validateAll(paySpendingContract);
if(!StringUtils.isBlank(msgPayIncomeContract)){
throw new JeroBootException(msgPayIncomeContract.toString());
}
List<PaySpendingContractInstallment> listPaySpendingContractInstallment = new ArrayList<>();
if(!CollectionUtils.isEmpty(input.getInstallment())){
listPaySpendingContractInstallment = input.getInstallment();
}
try {
LambdaQueryWrapper<PaySpendingContract> query = new LambdaQueryWrapper<>();
query.eq(PaySpendingContract::getContractNum,paySpendingContract.getContractNum());
PaySpendingContract paySpendingContractNew = paySpendingContractService.getOne(query);
if(!Objects.isNull(paySpendingContractNew)){
throw new JeroBootException("合同编号已存在!");
}
}catch (Exception e){
log.info("支出合同-添加异常",e);
throw new JeroBootException("合同编号已存在!");
}
setPaySpendingContract(paySpendingContract);
paySpendingContractService.save(paySpendingContract);
StringBuilder msgPaySpendingContractInstallment = new StringBuilder();
if(!CollectionUtils.isEmpty(listPaySpendingContractInstallment)){
List<PaySpendingContractInstallment> finalListPaySpendingContractInstallment = listPaySpendingContractInstallment;
listPaySpendingContractInstallment.forEach(p->{
p.setContractId(paySpendingContract.getId());
StringBuilder sb = ValidUtil.validateAll(p);
if(!StringUtils.isBlank(sb)){
msgPaySpendingContractInstallment.append("").append(finalListPaySpendingContractInstallment.indexOf(p)).append("阶段:").append(sb);
}
});
paySpendingContractInstallmentService.saveBatch(listPaySpendingContractInstallment);
}
if(!StringUtils.isBlank(msgPaySpendingContractInstallment)){
throw new JeroBootException(msgPaySpendingContractInstallment.toString());
}
return paySpendingContract;
}
@Override
public void editPayIncomeContractInput(PaySpendingContractInput input) {
if(Objects.isNull(input)){
throw new JeroBootException("支出合同信息不能为空!");
}
PaySpendingContract paySpendingContract = input.getContract();
if(Objects.isNull(input.getContract())){
throw new JeroBootException("支出合同信息不能为空!");
}
StringBuilder msgPayIncomeContract = ValidUtil.validateAll(paySpendingContract);
if(!StringUtils.isBlank(msgPayIncomeContract)){
throw new JeroBootException(msgPayIncomeContract.toString());
}
if(StringUtils.isBlank(paySpendingContract.getId())){
throw new JeroBootException("支出合同id不能为空!");
}
PaySpendingContract paySpendingContractStatus = paySpendingContractService.getById(paySpendingContract.getId());
if(Objects.isNull(paySpendingContractStatus)){
throw new JeroBootException("支出合同不存在!");
}
List<PaySpendingContractInstallment> listPaySpendingContractInstallment = new ArrayList<>();
if(!CollectionUtils.isEmpty(input.getInstallment())){
listPaySpendingContractInstallment = input.getInstallment();
}
try {
LambdaQueryWrapper<PaySpendingContract> query = new LambdaQueryWrapper<>();
query.eq(PaySpendingContract::getContractNum,paySpendingContract.getContractNum());
PaySpendingContract payIncomeContractNew = paySpendingContractService.getOne(query);
if(!Objects.isNull(payIncomeContractNew) && !Objects.equals(payIncomeContractNew.getId(),paySpendingContract.getId())){
throw new JeroBootException("合同编号已存在!");
}
}catch (Exception e){
log.info("支出合同-添加异常",e);
throw new JeroBootException("合同编号已存在!");
}
StringBuilder msgPaySpendingContractInstallment = new StringBuilder();
// 删除历史
LambdaQueryWrapper<PaySpendingContractInstallment> queryPaySpendingContractInstallmentService = new LambdaQueryWrapper<>();
queryPaySpendingContractInstallmentService.eq(PaySpendingContractInstallment::getContractId,paySpendingContract.getId());
List<PaySpendingContractInstallment> listPaySpendingContractInstallmentOld = paySpendingContractInstallmentService.list(queryPaySpendingContractInstallmentService);
if(!CollectionUtils.isEmpty(listPaySpendingContractInstallmentOld)){
List<String> list = listPaySpendingContractInstallmentOld.stream().map(PaySpendingContractInstallment::getId).collect(Collectors.toList());
paySpendingContractInstallmentService.removeByIds(list);
}
// 新增
if(!CollectionUtils.isEmpty(listPaySpendingContractInstallment)){
List<PaySpendingContractInstallment> finalListPayIncomeContractInstallment = listPaySpendingContractInstallment;
listPaySpendingContractInstallment.forEach(p->{
p.setContractId(paySpendingContract.getId());
StringBuilder sb = ValidUtil.validateAll(p);
if(!StringUtils.isBlank(sb)){
msgPaySpendingContractInstallment.append("").append(finalListPayIncomeContractInstallment.indexOf(p)).append("阶段:").append(sb);
}
});
paySpendingContractInstallmentService.saveBatch(listPaySpendingContractInstallment);
}
if(!StringUtils.isBlank(msgPaySpendingContractInstallment)){
throw new JeroBootException(msgPaySpendingContractInstallment.toString());
}
setPaySpendingContract(paySpendingContract);
paySpendingContractService.updateById(paySpendingContract);
}
@Override
public void deletePaySpendingContractInputById(String id) {
PaySpendingContract paySpendingContractStatus = paySpendingContractService.getById(id);
if(Objects.isNull(paySpendingContractStatus)){
throw new JeroBootException("支出合同不存在!");
}
paySpendingContractService.removeById(id);
LambdaUpdateWrapper<PaySpendingContractInstallment> updatePaySpendingContractInstallment = new LambdaUpdateWrapper<>();
updatePaySpendingContractInstallment.eq(PaySpendingContractInstallment::getContractId,id);
paySpendingContractInstallmentService.remove(updatePaySpendingContractInstallment);
}
@Override
public void deleteSpendingContractInputByIds(List<String> ids) {
LambdaQueryWrapper<PaySpendingContract> query = new LambdaQueryWrapper<>();
query.in(PaySpendingContract::getId,ids);
List<PaySpendingContract> listPaySpendingContractStatus = paySpendingContractService.list(query);
if(CollectionUtils.isEmpty(listPaySpendingContractStatus)){
throw new JeroBootException("收入合同不存在!");
}
paySpendingContractService.removeByIds(ids);
LambdaUpdateWrapper<PaySpendingContractInstallment> updatePaySpendingContractInstallment = new LambdaUpdateWrapper<>();
updatePaySpendingContractInstallment.in(PaySpendingContractInstallment::getContractId,ids);
paySpendingContractInstallmentService.remove(updatePaySpendingContractInstallment);
}
/**
* @Description 插入企业信息,联系人信息到临时表,更新项目记录
* @Author lqt
* @Date 2021/8/31
* @Param payCommonProject
* @Return
* @Exception
*/
private void setPaySpendingContract(PaySpendingContract paySpendingContract){
// 企业
PayCompanyManagementTemporary chargeCompanyName = payCompanyManagementTemporaryService.insertCompanyManagementTemporary(paySpendingContract.getSignedCompanyId());
if(Objects.isNull(chargeCompanyName)){
throw new JeroBootException("企业名称为空!");
}
// 联系人
PayContactsManagementTemporary contactsName = payContactsManagementTemporaryService.insertContactsManagementTemporary(paySpendingContract.getSignedContactsId());
if(Objects.isNull(contactsName)){
throw new JeroBootException("联系人名称为空!");
}
// 负责人名称
SysUser principalName = sysUserService.getById(paySpendingContract.getPrincipalId());
if(Objects.isNull(principalName)){
throw new JeroBootException("负责人名称为空!");
}
paySpendingContract.setPrincipalId(principalName.getId());
paySpendingContract.setPrincipalName(principalName.getRealname());
paySpendingContract.setSignedContactsTemporaryId(contactsName.getId());
paySpendingContract.setSignedContactsTemporaryName(contactsName.getName());
paySpendingContract.setSignedCompanyTemporaryId(chargeCompanyName.getId());
paySpendingContract.setSignedCompanyTemporaryName(chargeCompanyName.getCompanyName());
}
}
@@ -0,0 +1,23 @@
package com.jero.contract.vo;
import com.jero.contract.entity.PaySpendingContract;
import com.jero.contract.entity.PaySpendingContractInstallment;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
@Data
public class PaySpendingContractInput implements Serializable {
/**
* 合同数据
*/
@ApiModelProperty(value = "合同数据")
private PaySpendingContract contract;
/**
* 分期信息
*/
@ApiModelProperty(value = "分期信息")
private List<PaySpendingContractInstallment> installment;
}