Commit 24dc594b by HlQ

[add]

1.添加合同项目互相绑定和解绑接口
2.添加项目日志相关接口
3.添加批量导入任务和任务导出接口
4.用户列表接口添加 userid 字段
[fix] 结算差异联调以及 bug 修改
1 parent 0bb04771
...@@ -2,8 +2,6 @@ package vion.controller; ...@@ -2,8 +2,6 @@ package vion.controller;
import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.lang.Assert; import cn.hutool.core.lang.Assert;
import cn.hutool.core.lang.Opt;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjUtil; import cn.hutool.core.util.ObjUtil;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
...@@ -20,7 +18,7 @@ import vion.service.IRContractStoreService; ...@@ -20,7 +18,7 @@ import vion.service.IRContractStoreService;
import vion.vo.ContractVO; import vion.vo.ContractVO;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.Map;
/** /**
* 合同管理 * 合同管理
...@@ -63,44 +61,26 @@ public class ContractController { ...@@ -63,44 +61,26 @@ public class ContractController {
public String updateById(@PathVariable Long id, ContractDTO dto) { public String updateById(@PathVariable Long id, ContractDTO dto) {
return contractService.updateById(id, null, dto); return contractService.updateById(id, null, dto);
} }
@PostMapping("/contract/store") @PostMapping("/contract/store")
@SaCheckPermission(value = "contract:store:edit", orRole = "admin") @SaCheckPermission(value = "contract:store:save", orRole = "admin")
public String saveOrUpdateRContractStore(@RequestBody RContractStoreDTO dto) { public String bindStore(@RequestBody RContractStoreDTO dto) {
Assert.isFalse(ArrayUtil.isAllNotNull(dto.getStoreId(), dto.getContractId()), "合同id和项目id不能同时传值"); Assert.notNull(dto.getContractId(), "合同id不能为空");
if (ObjUtil.isNotNull(dto.getContractId())) { Assert.notNull(dto.getStoreId(), "项目id不能为空");
contractStoreService.lambdaUpdate() RContractStore contractStore = new RContractStore();
.eq(RContractStore::getContractId, dto.getContractId()) contractStore.setContractId(dto.getContractId());
.remove(); contractStore.setStoreId(dto.getStoreId());
Opt.ofEmptyAble(dto.getStoreIds()) return contractStoreService.save(contractStore) ? "绑定成功" : "绑定失败";
.ifPresent(storeIds -> { }
List<RContractStore> contractStoreList = storeIds.stream()
.map(storeId -> { @DeleteMapping("/contract/store")
RContractStore contractStore = new RContractStore(); @SaCheckPermission(value = "contract:store:remove", orRole = "admin")
contractStore.setContractId(dto.getContractId()); public String unbindStore(@RequestBody RContractStoreDTO dto) {
contractStore.setStoreId(storeId); Assert.notNull(dto.getContractId(), "合同id不能为空");
return contractStore; Assert.notNull(dto.getStoreId(), "项目id不能为空");
}).collect(Collectors.toList()); return contractStoreService.lambdaUpdate()
contractStoreService.saveBatch(contractStoreList); .eq(RContractStore::getContractId, dto.getContractId())
}); .eq(RContractStore::getStoreId, dto.getStoreId())
} .remove() ? "解绑成功" : "解绑失败";
if (ObjUtil.isNotNull(dto.getStoreId())) {
contractStoreService.lambdaUpdate()
.eq(RContractStore::getStoreId, dto.getStoreId())
.remove();
Opt.ofEmptyAble(dto.getContractIds())
.ifPresent(contractIds -> {
List<RContractStore> contractStoreList = contractIds.stream()
.map(contractId -> {
RContractStore contractStore = new RContractStore();
contractStore.setContractId(contractId);
contractStore.setStoreId(dto.getStoreId());
return contractStore;
}).collect(Collectors.toList());
contractStoreService.saveBatch(contractStoreList);
});
}
return "成功";
} }
@GetMapping("/contract/store") @GetMapping("/contract/store")
...@@ -120,34 +100,30 @@ public class ContractController { ...@@ -120,34 +100,30 @@ public class ContractController {
@GetMapping("/contract/analyze") @GetMapping("/contract/analyze")
@SaCheckPermission(value = "contract:analyze", orRole = "admin") @SaCheckPermission(value = "contract:analyze", orRole = "admin")
public Object analyze(ContractDTO dto) { public Map<String, Object> analyze(ContractDTO dto) {
return contractService.analyze(dto); return contractService.analyze(dto);
} }
@PostMapping("/contract/dispatch") @PostMapping("/contract/dispatch")
@SaCheckPermission(value = "contract:dispatch", orRole = "admin") @SaCheckPermission(value = "contract:dispatch", orRole = "admin")
// todo 未分配权限
public String dispatch(@RequestBody RContractTeamDTO dto) { public String dispatch(@RequestBody RContractTeamDTO dto) {
return contractService.dispatch(dto); return contractService.dispatch(dto);
} }
@GetMapping("/contract/sale") @GetMapping("/contract/sale")
@SaCheckPermission(value = "contract:sale:list", orRole = "admin") @SaCheckPermission(value = "contract:sale:list", orRole = "admin")
// todo 未分配权限
public Page<RContractUser> getSaleList(RContractUser dto) { public Page<RContractUser> getSaleList(RContractUser dto) {
return contractService.getSaleList(dto); return contractService.getSaleList(dto);
} }
@PostMapping("/contract/assignSale") @PostMapping("/contract/assignSale")
@SaCheckPermission(value = "contract:assignSale", orRole = "admin") @SaCheckPermission(value = "contract:assignSale", orRole = "admin")
// todo 未分配权限
public String assignSale(@RequestBody RContractUser dto) { public String assignSale(@RequestBody RContractUser dto) {
return contractService.assignSale(dto); return contractService.assignSale(dto);
} }
@PostMapping("/contract/unbindSale") @PostMapping("/contract/unbindSale")
@SaCheckPermission(value = "contract:unbindSale", orRole = "admin") @SaCheckPermission(value = "contract:unbindSale", orRole = "admin")
// todo 未分配权限
public String unbindSale(@RequestBody RContractUser dto) { public String unbindSale(@RequestBody RContractUser dto) {
return contractService.unbindSale(dto); return contractService.unbindSale(dto);
} }
...@@ -155,6 +131,7 @@ public class ContractController { ...@@ -155,6 +131,7 @@ public class ContractController {
@PostMapping("/contractSync") @PostMapping("/contractSync")
@SaCheckPermission(value = "contract:sync", orRole = "admin") @SaCheckPermission(value = "contract:sync", orRole = "admin")
public String manualSyncContract() { public String manualSyncContract() {
return contractRunner.contractSync() ? "成功" : "失败"; contractRunner.contractSync();
return "成功";
} }
} }
package vion.controller; package vion.controller;
import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.lang.Opt;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import vion.dto.SettlementDiffDTO; import vion.dto.SettlementDiffDTO;
import vion.model.FileInfo;
import vion.service.IFileService;
import vion.service.ISettlementDiffService; import vion.service.ISettlementDiffService;
import vion.vo.SettlementDiffVO; import vion.vo.SettlementDiffVO;
...@@ -19,9 +16,8 @@ import vion.vo.SettlementDiffVO; ...@@ -19,9 +16,8 @@ import vion.vo.SettlementDiffVO;
public class SettlementDiffController { public class SettlementDiffController {
private final ISettlementDiffService settlementDiffService; private final ISettlementDiffService settlementDiffService;
private final IFileService fileService;
@GetMapping("/settlementDiff/{no}") @GetMapping("/settlementDiff/list/{no}")
@SaCheckPermission(value = "settlementDiff:list", orRole = "admin") @SaCheckPermission(value = "settlementDiff:list", orRole = "admin")
public Page<SettlementDiffVO> list(@PathVariable String no, SettlementDiffDTO dto) { public Page<SettlementDiffVO> list(@PathVariable String no, SettlementDiffDTO dto) {
return settlementDiffService.list(no, dto); return settlementDiffService.list(no, dto);
...@@ -34,13 +30,13 @@ public class SettlementDiffController { ...@@ -34,13 +30,13 @@ public class SettlementDiffController {
@PostMapping("/settlementDiff") @PostMapping("/settlementDiff")
@SaCheckPermission(value = "settlementDiff:save", orRole = "admin") @SaCheckPermission(value = "settlementDiff:save", orRole = "admin")
public String save(@RequestBody SettlementDiffDTO dto) { public String save(SettlementDiffDTO dto) {
return settlementDiffService.save(dto); return settlementDiffService.save(dto);
} }
@PostMapping("/settlementDiff/{id}") @PostMapping("/settlementDiff/{id}")
@SaCheckPermission(value = "settlementDiff:edit", orRole = "admin") @SaCheckPermission(value = "settlementDiff:edit", orRole = "admin")
public String update(@PathVariable Long id, @RequestBody SettlementDiffDTO dto) { public String update(@PathVariable Long id, SettlementDiffDTO dto) {
dto.setId(id); dto.setId(id);
return settlementDiffService.update(id, dto); return settlementDiffService.update(id, dto);
} }
...@@ -49,12 +45,7 @@ public class SettlementDiffController { ...@@ -49,12 +45,7 @@ public class SettlementDiffController {
@SaCheckPermission(value = "settlementDiff:remove", orRole = "admin") @SaCheckPermission(value = "settlementDiff:remove", orRole = "admin")
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public String delById(@PathVariable Long id) { public String delById(@PathVariable Long id) {
Opt.ofEmptyAble(fileService.lambdaQuery() return settlementDiffService.delById(id);
.eq(FileInfo::getSourceId, id)
.eq(FileInfo::getType, 15)
.list())
.ifPresent(fileService::removeBatchByIds);
return settlementDiffService.removeById(id) ? "删除成功" : "删除失败";
} }
} }
...@@ -92,12 +92,11 @@ public class StoreController { ...@@ -92,12 +92,11 @@ public class StoreController {
@GetMapping("/store/manualCal") @GetMapping("/store/manualCal")
@SaCheckPermission(value = "store:calMaintainStatus", orRole = "admin") @SaCheckPermission(value = "store:calMaintainStatus", orRole = "admin")
// todo 权限未加,前端未调用该接口 // todo 权限未加,前端未使用到该接口
public String manualCalMaintainStatus() { public String manualCalMaintainStatus() {
return storeService.calMaintainStatus(); return storeService.calMaintainStatus();
} }
/*----------------------- todo 以下权限未加 ----------------------*/
@GetMapping("/store/user/{storeId}") @GetMapping("/store/user/{storeId}")
@SaCheckPermission(value = "store:user:list", orRole = "admin") @SaCheckPermission(value = "store:user:list", orRole = "admin")
public List<RStoreUser> getUserList(@PathVariable Long storeId) { public List<RStoreUser> getUserList(@PathVariable Long storeId) {
...@@ -115,8 +114,10 @@ public class StoreController { ...@@ -115,8 +114,10 @@ public class StoreController {
@GetMapping("/store/log/{storeId}") @GetMapping("/store/log/{storeId}")
@SaCheckPermission(value = "store:log:list", orRole = "admin") @SaCheckPermission(value = "store:log:list", orRole = "admin")
public List<StoreLog> getLogList(@PathVariable Long storeId) { public Page<StoreLog> getLogList(@PathVariable Long storeId, StoreLog storeLog) {
return storeLogService.lambdaQuery().eq(StoreLog::getStoreId, storeId).list(); storeLog.setStoreId(storeId);
return storeLogService.lambdaQuery(storeLog)
.page(Page.of(storeLog.getPageNum(), storeLog.getPageSize()));
} }
@PostMapping("/store/log") @PostMapping("/store/log")
...@@ -125,6 +126,19 @@ public class StoreController { ...@@ -125,6 +126,19 @@ public class StoreController {
return storeLogService.save(storeLog) ? "新增成功" : "新增失败"; return storeLogService.save(storeLog) ? "新增成功" : "新增失败";
} }
@DeleteMapping("/store/log/{logId}")
@SaCheckPermission(value = "store:log:delete", orRole = "admin")
public String delLog(@PathVariable Long logId) {
return storeLogService.removeById(logId) ? "删除成功" : "删除失败";
}
@PostMapping("/store/log/{logId}")
@SaCheckPermission(value = "store:log:edit", orRole = "admin")
public String updateLog(@PathVariable Long logId, @RequestBody StoreLog storeLog) {
storeLog.setId(logId);
return storeLogService.updateById(storeLog) ? "更新成功" : "更新失败";
}
@GetMapping("/store/screen") @GetMapping("/store/screen")
@SaCheckPermission(value = "store:screen", orRole = "admin") @SaCheckPermission(value = "store:screen", orRole = "admin")
public List<StoreVO> storeScreen() { public List<StoreVO> storeScreen() {
......
...@@ -76,14 +76,12 @@ public class TaskController { ...@@ -76,14 +76,12 @@ public class TaskController {
@PostMapping("/task/batchIns") @PostMapping("/task/batchIns")
@SaCheckPermission(value = "task:batchIns", orRole = "admin") @SaCheckPermission(value = "task:batchIns", orRole = "admin")
// todo 未加权限
public String batchIns(@RequestBody List<TaskDTO> data) { public String batchIns(@RequestBody List<TaskDTO> data) {
return taskService.batchIns(data); return taskService.batchIns(data);
} }
@GetMapping("/task/export") @GetMapping("/task/export")
@SaCheckPermission(value = "task:export", orRole = "admin") @SaCheckPermission(value = "task:export", orRole = "admin")
// todo 未加权限
public void defaultBuild(TaskDTO data, HttpServletResponse response) { public void defaultBuild(TaskDTO data, HttpServletResponse response) {
UserVO user = (UserVO) StpUtil.getTokenSession().get("curLoginUser"); UserVO user = (UserVO) StpUtil.getTokenSession().get("curLoginUser");
data.setPageSize(9999); data.setPageSize(9999);
......
...@@ -56,7 +56,7 @@ public class UserController { ...@@ -56,7 +56,7 @@ public class UserController {
@GetMapping("/user/onlyName") @GetMapping("/user/onlyName")
@SaCheckPermission(value = "user:listName", orRole = "admin") @SaCheckPermission(value = "user:listName", orRole = "admin")
public List<UserVO> getNameList(UserDTO dto) { public List<UserVO> getNameList(UserDTO dto) {
return converter.convert(userService.list(Wrappers.lambdaQuery(converter.convert(dto, new User())).select(User::getId, User::getUsername, User::getPreWorkOrder)), UserVO.class); return converter.convert(userService.list(Wrappers.lambdaQuery(converter.convert(dto, new User())).select(User::getId, User::getUserid, User::getUsername, User::getPreWorkOrder)), UserVO.class);
} }
@GetMapping("/user") @GetMapping("/user")
......
...@@ -38,7 +38,7 @@ public class ContractRunner { ...@@ -38,7 +38,7 @@ public class ContractRunner {
private final RedisTemplate redisTemplate; private final RedisTemplate redisTemplate;
@Scheduled(cron = "0 0 * * * *") @Scheduled(cron = "0 0 * * * *")
public Boolean contractSync() { public void contractSync() {
log.info("【开始】从crm系统同步合同信息"); log.info("【开始】从crm系统同步合同信息");
Map<String, Contract> no2ContactMap = contractService.list().stream().collect(Collectors.toMap(Contract::getContractNo, Function.identity())); Map<String, Contract> no2ContactMap = contractService.list().stream().collect(Collectors.toMap(Contract::getContractNo, Function.identity()));
Map<String, Integer> contractTypeMap = dictionaryService.lambdaQuery().eq(Dictionary::getType, "contract_type").list() Map<String, Integer> contractTypeMap = dictionaryService.lambdaQuery().eq(Dictionary::getType, "contract_type").list()
...@@ -105,17 +105,19 @@ public class ContractRunner { ...@@ -105,17 +105,19 @@ public class ContractRunner {
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("合同信息同步失败:", e); log.error("合同信息同步失败:", e);
return false; return;
} }
if (CollUtil.isEmpty(insOrUpdContractList)) { if (CollUtil.isEmpty(insOrUpdContractList)) {
log.info("没有需要插入或更新的合同"); log.info("没有需要插入或更新的合同");
return true; return;
} }
insOrUpdContractList.forEach(v -> { insOrUpdContractList.forEach(v -> {
if (no2ContactMap.containsKey(v.getContractNo())) { if (no2ContactMap.containsKey(v.getContractNo())) {
v.setId(no2ContactMap.get(v.getContractNo()).getId()); v.setId(no2ContactMap.get(v.getContractNo()).getId());
// 已有合同不更新状态
v.setStatus(null);
} }
}); });
contractService.saveOrUpdateBatch(insOrUpdContractList, 500); contractService.saveOrUpdateBatch(insOrUpdContractList, 500);
...@@ -213,7 +215,6 @@ public class ContractRunner { ...@@ -213,7 +215,6 @@ public class ContractRunner {
log.info("【结束】从crm系统同步合同信息"); log.info("【结束】从crm系统同步合同信息");
redisTemplate.opsForValue().set("contract:sync:time", DateUtil.formatDateTime(insOrUpdContractList.get(0).getOriginalModTime())); redisTemplate.opsForValue().set("contract:sync:time", DateUtil.formatDateTime(insOrUpdContractList.get(0).getOriginalModTime()));
return true;
} }
@Scheduled(cron = "0 0 1 * * ?") @Scheduled(cron = "0 0 1 * * ?")
......
package vion.dto; package vion.dto;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
...@@ -10,6 +11,8 @@ import lombok.Setter; ...@@ -10,6 +11,8 @@ import lombok.Setter;
@Getter @Getter
@Setter @Setter
public class BaseDTO { public class BaseDTO {
private Integer pageNum = 1; @JsonIgnore
private Integer pageSize = 10; private transient Integer pageNum = 1;
@JsonIgnore
private transient Integer pageSize = 10;
} }
package vion.model; package vion.model;
import com.baomidou.mybatisplus.annotation.*; import com.baomidou.mybatisplus.annotation.*;
import io.github.linpeilie.annotations.AutoMapper; import io.github.linpeilie.annotations.*;
import io.github.linpeilie.annotations.AutoMappers;
import lombok.Data; import lombok.Data;
import vion.dto.ContractDTO; import vion.dto.ContractDTO;
import vion.vo.ContractVO; import vion.vo.ContractVO;
...@@ -70,12 +69,14 @@ public class Contract { ...@@ -70,12 +69,14 @@ public class Contract {
* 合同总金额 * 合同总金额
*/ */
@TableField(value = "total_amount") @TableField(value = "total_amount")
@ReverseAutoMapping(targetClass = ContractDTO.class, ignore = true)
private BigDecimal totalAmount; private BigDecimal totalAmount;
/** /**
* 合同已收金额 * 合同已收金额
*/ */
@TableField(value = "paid_amount") @TableField(value = "paid_amount")
@ReverseAutoMapping(targetClass = ContractDTO.class, ignore = true)
private BigDecimal paidAmount; private BigDecimal paidAmount;
/** /**
...@@ -83,12 +84,14 @@ public class Contract { ...@@ -83,12 +84,14 @@ public class Contract {
* 根据【合同进度】,由系统判断出应该收到的金额 * 根据【合同进度】,由系统判断出应该收到的金额
*/ */
@TableField(value = "receivable_amount") @TableField(value = "receivable_amount")
@ReverseAutoMapping(targetClass = ContractDTO.class, ignore = true)
private BigDecimal receivableAmount; private BigDecimal receivableAmount;
/** /**
* 合同未收金额:total-paid * 合同未收金额:total-paid
*/ */
@TableField(value = "outstanding_amount") @TableField(value = "outstanding_amount")
@ReverseAutoMapping(targetClass = ContractDTO.class, ignore = true)
private BigDecimal outstandingAmount; private BigDecimal outstandingAmount;
/** /**
......
...@@ -33,7 +33,7 @@ public class RContractUser extends BaseDTO { ...@@ -33,7 +33,7 @@ public class RContractUser extends BaseDTO {
* 用户id,用钉钉的userid * 用户id,用钉钉的userid
*/ */
@TableField(value = "user_id") @TableField(value = "user_id")
private Integer userId; private String userId;
/** /**
* 用户名 * 用户名
......
...@@ -3,6 +3,8 @@ package vion.model; ...@@ -3,6 +3,8 @@ package vion.model;
import com.baomidou.mybatisplus.annotation.*; import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data; import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import vion.dto.BaseDTO;
import java.util.Date; import java.util.Date;
...@@ -11,7 +13,7 @@ import java.util.Date; ...@@ -11,7 +13,7 @@ import java.util.Date;
*/ */
@Data @Data
@TableName(value = "tbl_store_log") @TableName(value = "tbl_store_log")
public class StoreLog { public class StoreLog extends BaseDTO {
@TableId(value = "id", type = IdType.AUTO) @TableId(value = "id", type = IdType.AUTO)
private Long id; private Long id;
...@@ -25,6 +27,7 @@ public class StoreLog { ...@@ -25,6 +27,7 @@ public class StoreLog {
* 日志日期 * 日志日期
*/ */
@TableField(value = "log_date") @TableField(value = "log_date")
@DateTimeFormat(pattern = "yyyy-MM-dd")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date logDate; private Date logDate;
......
...@@ -11,6 +11,8 @@ import vion.model.Contract; ...@@ -11,6 +11,8 @@ import vion.model.Contract;
import vion.model.RContractUser; import vion.model.RContractUser;
import vion.vo.ContractVO; import vion.vo.ContractVO;
import java.util.Map;
/** /**
* @author HlQ * @author HlQ
* @date 2023/11/29 * @date 2023/11/29
...@@ -29,7 +31,7 @@ public interface IContractService extends MPJBaseService<Contract>{ ...@@ -29,7 +31,7 @@ public interface IContractService extends MPJBaseService<Contract>{
JSONObject calAmount(ContractDTO dto); JSONObject calAmount(ContractDTO dto);
Object analyze(ContractDTO dto); Map<String, Object> analyze(ContractDTO dto);
String dispatch(@RequestBody RContractTeamDTO dto); String dispatch(@RequestBody RContractTeamDTO dto);
......
...@@ -2,6 +2,7 @@ package vion.service; ...@@ -2,6 +2,7 @@ package vion.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseService; import com.github.yulichang.base.MPJBaseService;
import org.springframework.web.bind.annotation.PathVariable;
import vion.dto.SettlementDiffDTO; import vion.dto.SettlementDiffDTO;
import vion.model.SettlementDiff; import vion.model.SettlementDiff;
import vion.vo.SettlementDiffVO; import vion.vo.SettlementDiffVO;
...@@ -20,4 +21,6 @@ public interface ISettlementDiffService extends MPJBaseService<SettlementDiff> { ...@@ -20,4 +21,6 @@ public interface ISettlementDiffService extends MPJBaseService<SettlementDiff> {
String update(Long id, SettlementDiffDTO dto); String update(Long id, SettlementDiffDTO dto);
String delById(@PathVariable Long id);
} }
...@@ -53,7 +53,7 @@ public class ContractPaymentServiceImpl extends MPJBaseServiceImpl<ContractPayme ...@@ -53,7 +53,7 @@ public class ContractPaymentServiceImpl extends MPJBaseServiceImpl<ContractPayme
BigDecimal curAmount = NumberUtil.mul(totalAmount, sumRatio); BigDecimal curAmount = NumberUtil.mul(totalAmount, sumRatio);
BigDecimal paidAmount = ObjUtil.isNull(dto.getPaidAmount()) ? existContract.getPaidAmount() : dto.getPaidAmount(); BigDecimal paidAmount = ObjUtil.isNull(dto.getPaidAmount()) ? existContract.getPaidAmount() : dto.getPaidAmount();
BigDecimal recAmount = NumberUtil.add(NumberUtil.sub(curAmount, paidAmount), diffAmount2); BigDecimal recAmount = NumberUtil.add(NumberUtil.sub(curAmount, paidAmount), diffAmount2);
BigDecimal outsideAmount = NumberUtil.add(NumberUtil.sub(totalAmount, paidAmount), NumberUtil.add(diffAmount1, diffAmount2)); BigDecimal outsideAmount = NumberUtil.sub(totalAmount, paidAmount);
dto.setReceivableAmount(recAmount); dto.setReceivableAmount(recAmount);
dto.setOutstandingAmount(outsideAmount); dto.setOutstandingAmount(outsideAmount);
} }
......
...@@ -12,7 +12,6 @@ import cn.hutool.core.lang.Opt; ...@@ -12,7 +12,6 @@ import cn.hutool.core.lang.Opt;
import cn.hutool.core.map.MapUtil; import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.*; import cn.hutool.core.util.*;
import cn.hutool.crypto.SecureUtil; import cn.hutool.crypto.SecureUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
...@@ -63,57 +62,12 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont ...@@ -63,57 +62,12 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
@Override @Override
public Page<ContractVO> list(ContractDTO dto) { public Page<ContractVO> list(ContractDTO dto) {
Contract contract = converter.convert(dto, Contract.class); Result result = getResult(dto);
// fixme 关联查询,查出多条一样的记录
List<Long> contractIdList = dto.getSwitchFlag() == 1 ? Page<ContractVO> contractVOList = this.selectJoinListPage(Page.of(dto.getPageNum(), dto.getPageSize()), ContractVO.class, result.wrapper);
contractStoreService.listObjs(Wrappers.<RContractStore>lambdaQuery()
.select(RContractStore::getContractId), o -> Long.valueOf(o.toString()))
: ListUtil.empty();
List<Long> relatedContractIdList = Opt.ofNullable(dto.getProductLine())
.map(pl -> Db.listObjs(Wrappers.lambdaQuery(Store.class).eq(Store::getProductLine, pl), Store::getId))
.map(storeIds -> contractStoreService.listObjs(Wrappers.<RContractStore>lambdaQuery().select(RContractStore::getContractId).in(RContractStore::getStoreId, storeIds), o -> Long.valueOf(o.toString())))
.orElse(ListUtil.empty());
UserVO userVO = (UserVO) StpUtil.getTokenSession().get("curLoginUser");
Set<String> roleCodeList = Opt.ofEmptyAble(userVO.getRoleVOList())
.map(l -> l.stream().map(RoleVO::getCode).collect(Collectors.toSet()))
.orElse(CollUtil.newHashSet());
String saleName = Opt.ofEmptyAble(roleCodeList)
.map(rc -> {
if (!rc.contains("admin") && !rc.contains("shangwu") && !rc.contains("caiwu")) {
return userVO.getUsername();
} else {
return "";
}
}).orElse("未知");
// 防止特殊情况出现
Assert.notEquals(saleName, "未知", "当前用户角色不详,请联系管理员");
// todo r_contract_user关联表查当前人(数据权限)所有合同id
MPJLambdaWrapper<Contract> wrapper = new MPJLambdaWrapper<>(contract)
.selectAll(Contract.class)
.leftJoin(RContractUser.class, RContractUser::getContractId, Contract::getId)
.between(ArrayUtil.isAllNotNull(dto.getSignDateStart(), dto.getSignDateEnd()), Contract::getSignDate, dto.getSignDateStart(), dto.getSignDateEnd())
.notIn(CollUtil.isNotEmpty(contractIdList), Contract::getId, contractIdList)
.in(CollUtil.isNotEmpty(relatedContractIdList), Contract::getId, relatedContractIdList)
.eq(StrUtil.isNotBlank(saleName), Contract::getSaleName, saleName)
.or()
.eq(StrUtil.isNotBlank(saleName), RContractUser::getUsername, saleName)
.orderByDesc(Contract::getEntryTime);
if (StrUtil.isNotBlank(dto.getOperator()) && ObjUtil.isNotNull(dto.getAmount())) {
String ope = dto.getOperator();
if (">".equals(ope)) {
wrapper.gt(getCol(dto), dto.getAmount());
} else if ("<".equals(ope)) {
wrapper.lt(getCol(dto), dto.getAmount());
} else {
wrapper.eq(getCol(dto), dto.getAmount());
}
}
Page<Contract> contractList = this.page(Page.of(dto.getPageNum(), dto.getPageSize()), wrapper); if (!result.roleCodeList.contains("admin") && !result.roleCodeList.contains("xiaoshou") && !result.roleCodeList.contains("caiwu")) {
List<ContractVO> contractVOList = converter.convert(contractList.getRecords(), ContractVO.class); contractVOList.getRecords().forEach(vo -> {
if (!roleCodeList.contains("admin") && !roleCodeList.contains("xiaoshou") && !roleCodeList.contains("caiwu")) {
contractVOList.forEach(vo -> {
vo.setTotalAmount(null); vo.setTotalAmount(null);
vo.setPaidAmount(null); vo.setPaidAmount(null);
vo.setReceivableAmount(null); vo.setReceivableAmount(null);
...@@ -121,43 +75,32 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont ...@@ -121,43 +75,32 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
vo.setInvoiceAmount(null); vo.setInvoiceAmount(null);
}); });
} }
// 查出合同关联的项目名 completeStoreName(contractVOList.getRecords());
completeStoreName(contractVOList); return contractVOList;
return Page.<ContractVO>of(contractList.getCurrent(), contractList.getSize(), contractList.getTotal()).setRecords(contractVOList);
}
private SFunction<Contract, Object> getCol(ContractDTO dto) {
if (dto.getTotalAmount() != null) {
return Contract::getTotalAmount;
} else if (dto.getPaidAmount() != null) {
return Contract::getPaidAmount;
} else if (dto.getReceivableAmount() != null) {
return Contract::getReceivableAmount;
} else {
return Contract::getOutstandingAmount;
}
} }
@Override @Override
public Page<ContractVO> listPart(ContractDTO dto) { public Page<ContractVO> listPart(ContractDTO dto) {
Contract contract = converter.convert(dto, Contract.class);
List<Long> ids = Opt.ofNullable(dto.getStoreId()) List<Long> ids = Opt.ofNullable(dto.getStoreId())
.map(storeId -> contractStoreService.listObjs(Wrappers.<RContractStore>lambdaQuery().select(RContractStore::getContractId).eq(RContractStore::getStoreId, dto.getStoreId()), o -> Long.valueOf(o.toString()))) .map(storeId -> contractStoreService.listObjs(Wrappers.<RContractStore>lambdaQuery().select(RContractStore::getContractId).eq(RContractStore::getStoreId, dto.getStoreId()), o -> Long.valueOf(o.toString())))
.filter(CollUtil::isNotEmpty) .filter(CollUtil::isNotEmpty)
.orElse(ListUtil.of(0L)); .orElse(ListUtil.of(0L));
Page<Contract> contractList = this.lambdaQuery(contract) Page<Contract> contractList = this.lambdaQuery(converter.convert(dto, Contract.class))
.select(Contract::getId, Contract::getName, Contract::getContractNo, Contract::getType, Contract::getSignDate, Contract::getWarrantyPeriod, Contract::getFinalDate, Contract::getStatus, Contract::getSaleName, Contract::getCustomerName, Contract::getMaintainSdate, Contract::getMaintainEdate) .select(Contract::getId, Contract::getName, Contract::getContractNo, Contract::getType, Contract::getSignDate, Contract::getWarrantyPeriod, Contract::getFinalDate, Contract::getStatus, Contract::getSaleName, Contract::getCustomerName, Contract::getMaintainSdate, Contract::getMaintainEdate)
.in(CollUtil.isNotEmpty(ids), Contract::getId, ids) .in(CollUtil.isNotEmpty(ids), Contract::getId, ids)
.orderByDesc(Contract::getEntryTime) .orderByDesc(Contract::getEntryTime)
.page(Page.of(dto.getPageNum(), dto.getPageSize())); .page(Page.of(dto.getPageNum(), dto.getPageSize()));
List<ContractVO> contractVOList = converter.convert(contractList.getRecords(), ContractVO.class); List<ContractVO> contractVOList = converter.convert(contractList.getRecords(), ContractVO.class);
// 查出合同关联的项目名
completeStoreName(contractVOList); completeStoreName(contractVOList);
return Page.<ContractVO>of(contractList.getCurrent(), contractList.getSize(), contractList.getTotal()).setRecords(contractVOList); return Page.<ContractVO>of(contractList.getCurrent(), contractList.getSize(), contractList.getTotal()).setRecords(contractVOList);
} }
/**
* 查出合同关联的项目名
*
* @param contractVOList list
*/
private void completeStoreName(List<ContractVO> contractVOList) { private void completeStoreName(List<ContractVO> contractVOList) {
Map<Long, List<Long>> contractStoreIdsMap = Opt.ofEmptyAble(contractVOList) Map<Long, List<Long>> contractStoreIdsMap = Opt.ofEmptyAble(contractVOList)
.map(list -> list.stream().map(ContractVO::getId).collect(Collectors.toList())) .map(list -> list.stream().map(ContractVO::getId).collect(Collectors.toList()))
...@@ -305,25 +248,7 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont ...@@ -305,25 +248,7 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
@Override @Override
public JSONObject calAmount(ContractDTO dto) { public JSONObject calAmount(ContractDTO dto) {
UserVO userVO = (UserVO) StpUtil.getTokenSession().get("curLoginUser"); Result result = getResult(dto);
Set<String> roleCodeList = Opt.ofEmptyAble(userVO.getRoleVOList())
.map(l -> l.stream().map(RoleVO::getCode).collect(Collectors.toSet()))
.orElse(CollUtil.newHashSet());
String saleName = Opt.ofEmptyAble(roleCodeList)
.map(rc -> {
if (!rc.contains("admin") && !rc.contains("shangwu") && !rc.contains("caiwu")) {
return userVO.getUsername();
} else {
return "";
}
}).orElse("未知");
// 防止特殊情况出现
Assert.notEquals(saleName, "未知", "当前用户角色不详,请联系管理员");
List<Long> relatedContractIdList = Opt.ofNullable(dto.getProductLine())
.map(pl -> Db.listObjs(Wrappers.lambdaQuery(Store.class).eq(Store::getProductLine, pl), Store::getId))
.map(storeIds -> contractStoreService.listObjs(Wrappers.<RContractStore>lambdaQuery().select(RContractStore::getContractId).in(RContractStore::getStoreId, storeIds), o -> Long.valueOf(o.toString())))
.orElse(ListUtil.empty());
JSONObject obj = JSONUtil.createObj() JSONObject obj = JSONUtil.createObj()
.set("totalAmount", 0) .set("totalAmount", 0)
...@@ -331,20 +256,10 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont ...@@ -331,20 +256,10 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
.set("recAmount", 0) .set("recAmount", 0)
.set("outAmount", 0) .set("outAmount", 0)
.set("invoiceAmount", 0); .set("invoiceAmount", 0);
if (!result.roleCodeList.contains("admin") && !result.roleCodeList.contains("xiaoshou") && !result.roleCodeList.contains("caiwu")) {
if (!roleCodeList.contains("admin") && !roleCodeList.contains("xiaoshou") && !roleCodeList.contains("caiwu")) {
return obj; return obj;
} }
List<Contract> contracts = this.selectJoinList(Contract.class, result.wrapper);
MPJLambdaWrapper<Contract> wrapper = new MPJLambdaWrapper<>(converter.convert(dto, Contract.class))
.selectAll(Contract.class)
.leftJoin(RContractUser.class, RContractUser::getContractId, Contract::getId)
.eq(StrUtil.isNotBlank(saleName), Contract::getSaleName, saleName)
.or()
.eq(StrUtil.isNotBlank(saleName), RContractUser::getUsername, saleName)
.in(CollUtil.isNotEmpty(relatedContractIdList), Contract::getId, relatedContractIdList)
.between(ArrayUtil.isAllNotNull(dto.getSignDateStart(), dto.getSignDateEnd()), Contract::getSignDate, dto.getSignDateStart(), dto.getSignDateEnd());
List<Contract> contracts = this.selectJoinList(Contract.class, wrapper);
Opt.ofEmptyAble(contracts) Opt.ofEmptyAble(contracts)
.ifPresent(list -> { .ifPresent(list -> {
...@@ -367,21 +282,24 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont ...@@ -367,21 +282,24 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
} }
@Override @Override
public Object analyze(ContractDTO dto) { public Map<String, Object> analyze(ContractDTO dto) {
List<Contract> contractList = this.lambdaQuery(converter.convert(dto, Contract.class)) List<Contract> contractList = this.lambdaQuery(converter.convert(dto, Contract.class))
.ge(Contract::getReceivableAmount, 0) .gt(Contract::getReceivableAmount, 0)
.gt(Contract::getTotalAmount, 0)
.between(ArrayUtil.isAllNotNull(dto.getSignDateStart(), dto.getSignDateEnd()), Contract::getSignDate, dto.getSignDateStart(), dto.getSignDateEnd()) .between(ArrayUtil.isAllNotNull(dto.getSignDateStart(), dto.getSignDateEnd()), Contract::getSignDate, dto.getSignDateStart(), dto.getSignDateEnd())
.list(); .list();
if (CollUtil.isEmpty(contractList)) { if (CollUtil.isEmpty(contractList)) {
return ListUtil.empty(); return new JSONObject();
} }
// todo 优化查询,当下是查询所有 // todo 优化查询,当下是查询所有
Map<Long, List<ContractPayment>> id2PaymentMap = Opt.ofEmptyAble(contractPaymentService.lambdaQuery().gt(ContractPayment::getPaymentRatio, 0).list()) Map<Long, List<ContractPayment>> id2PaymentMap = Opt.ofEmptyAble(contractPaymentService
.lambdaQuery().gt(ContractPayment::getPaymentRatio, 0)
.list())
.map(list -> list.stream().collect(Collectors.groupingBy(ContractPayment::getContractId))) .map(list -> list.stream().collect(Collectors.groupingBy(ContractPayment::getContractId)))
.orElse(MapUtil.empty()); .orElse(MapUtil.empty());
if (MapUtil.isEmpty(id2PaymentMap)) { if (MapUtil.isEmpty(id2PaymentMap)) {
return ListUtil.empty(); return new JSONObject();
} }
List<FinancialAgeVO> financialAgeVOList = new ArrayList<>(); List<FinancialAgeVO> financialAgeVOList = new ArrayList<>();
...@@ -391,13 +309,10 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont ...@@ -391,13 +309,10 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
return; return;
} }
BigDecimal totalAmount = c.getTotalAmount(); BigDecimal totalAmount = c.getTotalAmount();
if (NumberUtil.equals(totalAmount, BigDecimal.ZERO)) {
return;
}
BigDecimal paidAmount = c.getPaidAmount(); BigDecimal paidAmount = c.getPaidAmount();
Map<Integer, Date> type2DateMap = contractPaymentList.stream().filter(cp -> cp.getPaymentType() < c.getStatus()).collect(HashMap::new, (m, v) -> m.put(v.getPaymentType(), v.getNodeDate()), HashMap::putAll); Map<Integer, Date> type2DateMap = contractPaymentList.stream().filter(cp -> cp.getPaymentType() <= c.getStatus()).collect(HashMap::new, (m, v) -> m.put(v.getPaymentType(), v.getPaymentDate()), HashMap::putAll);
Map<Integer, BigDecimal> type2AmountMap = contractPaymentList.stream().filter(cp -> cp.getPaymentType() < c.getStatus()).collect(Collectors.toMap(ContractPayment::getPaymentType, v -> NumberUtil.mul(v.getPaymentRatio(), totalAmount))); Map<Integer, BigDecimal> type2AmountMap = contractPaymentList.stream().filter(cp -> cp.getPaymentType() <= c.getStatus()).collect(Collectors.toMap(ContractPayment::getPaymentType, v -> NumberUtil.mul(v.getPaymentRatio(), totalAmount)));
TreeMap<Integer, BigDecimal> sortMap = MapUtil.sort(type2AmountMap, Comparator.comparingInt(Integer::intValue)); TreeMap<Integer, BigDecimal> sortMap = MapUtil.sort(type2AmountMap, Comparator.comparingInt(Integer::intValue));
for (Map.Entry<Integer, BigDecimal> entry : sortMap.entrySet()) { for (Map.Entry<Integer, BigDecimal> entry : sortMap.entrySet()) {
...@@ -427,9 +342,14 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont ...@@ -427,9 +342,14 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
} }
} }
}); });
Map<String, Object> map = MapUtil.<String, Object>builder()
.put("totalAmount", financialAgeVOList.stream().map(FinancialAgeVO::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add)).build();
// 手动分页 // 手动分页
int[] transToStartEnd = PageUtil.transToStartEnd(dto.getPageNum() - 1, dto.getPageSize()); int[] transToStartEnd = PageUtil.transToStartEnd(dto.getPageNum() - 1, dto.getPageSize());
return Page.<FinancialAgeVO>of(dto.getPageNum(), dto.getPageSize(), financialAgeVOList.size()).setRecords(CollUtil.sub(financialAgeVOList, transToStartEnd[0], transToStartEnd[1])); Page<FinancialAgeVO> financialAgeVOPage = Page.<FinancialAgeVO>of(dto.getPageNum(), dto.getPageSize(), financialAgeVOList.size())
.setRecords(CollUtil.sub(financialAgeVOList, transToStartEnd[0], transToStartEnd[1]));
map.put("list", financialAgeVOPage);
return map;
} }
@Override @Override
...@@ -459,6 +379,68 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont ...@@ -459,6 +379,68 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
return contractUserService.remove(Wrappers.<RContractUser>lambdaQuery().eq(RContractUser::getContractId, contractUser.getContractId()).eq(RContractUser::getUserId, contractUser.getUserId())) ? "解绑成功" : "解绑失败"; return contractUserService.remove(Wrappers.<RContractUser>lambdaQuery().eq(RContractUser::getContractId, contractUser.getContractId()).eq(RContractUser::getUserId, contractUser.getUserId())) ? "解绑成功" : "解绑失败";
} }
private Result getResult(ContractDTO dto) {
// 查询已关联项目的合同id
List<Long> contractIdList = dto.getSwitchFlag() == 1 ?
contractStoreService.listObjs(Wrappers.<RContractStore>lambdaQuery()
.select(RContractStore::getContractId), o -> Long.valueOf(o.toString()))
: ListUtil.empty();
// 根据产品线查出关联的合同
List<Long> relatedContractIdList = Opt.ofNullable(dto.getProductLine())
.map(pl -> Db.listObjs(Wrappers.lambdaQuery(Store.class).eq(Store::getProductLine, pl), Store::getId))
.map(storeIds -> contractStoreService.listObjs(Wrappers.<RContractStore>lambdaQuery().select(RContractStore::getContractId).in(RContractStore::getStoreId, storeIds), o -> Long.valueOf(o.toString())))
.orElse(ListUtil.empty());
// 根据当前登录用户的角色获取用户名
UserVO userVO = (UserVO) StpUtil.getTokenSession().get("curLoginUser");
Set<String> roleCodeList = Opt.ofEmptyAble(userVO.getRoleVOList())
.map(l -> l.stream().map(RoleVO::getCode).collect(Collectors.toSet()))
.orElse(CollUtil.newHashSet());
Assert.notEmpty(roleCodeList, "当前用户角色不详,请联系管理员");
String saleName = "";
if (!roleCodeList.contains("admin") && !roleCodeList.contains("shangwu") && !roleCodeList.contains("caiwu")) {
saleName = userVO.getUsername();
}
// 查询当前销售关联的合同
List<Long> contractUserIdList = Opt.ofBlankAble(saleName)
.map(name -> contractUserService.listObjs(Wrappers.<RContractUser>lambdaQuery()
.select(RContractUser::getContractId).eq(RContractUser::getUsername, name), o -> Long.valueOf(o.toString())))
.orElse(ListUtil.empty());
MPJLambdaWrapper<Contract> wrapper = new MPJLambdaWrapper<>(converter.convert(dto, Contract.class))
.selectAll(Contract.class)
.eq(StrUtil.isNotBlank(saleName), Contract::getSaleName, saleName)
.notIn(CollUtil.isNotEmpty(contractIdList), Contract::getId, contractIdList)
.in(CollUtil.isNotEmpty(relatedContractIdList), Contract::getId, relatedContractIdList)
.or()
.in(CollUtil.isNotEmpty(contractUserIdList), Contract::getId, contractUserIdList)
.between(ArrayUtil.isAllNotNull(dto.getSignDateStart(), dto.getSignDateEnd()), Contract::getSignDate, dto.getSignDateStart(), dto.getSignDateEnd())
.orderByDesc(Contract::getEntryTime);
if (StrUtil.isNotBlank(dto.getOperator()) && ObjUtil.isNotNull(dto.getAmount())) {
String ope = dto.getOperator();
if (">".equals(ope)) {
wrapper.gt(getCol(dto), dto.getAmount());
} else if ("<".equals(ope)) {
wrapper.lt(getCol(dto), dto.getAmount());
} else {
wrapper.eq(getCol(dto), dto.getAmount());
}
}
return new Result(roleCodeList, wrapper);
}
private SFunction<Contract, Object> getCol(ContractDTO dto) {
if (dto.getTotalAmount() != null) {
return Contract::getTotalAmount;
} else if (dto.getPaidAmount() != null) {
return Contract::getPaidAmount;
} else if (dto.getReceivableAmount() != null) {
return Contract::getReceivableAmount;
} else {
return Contract::getOutstandingAmount;
}
}
JSONObject buildMsg(String userid, Contract contract, String applicantName) { JSONObject buildMsg(String userid, Contract contract, String applicantName) {
JSONObject jsonObj = new JSONObject(); JSONObject jsonObj = new JSONObject();
jsonObj.set("agent_id", 2358374016L); jsonObj.set("agent_id", 2358374016L);
...@@ -473,16 +455,20 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont ...@@ -473,16 +455,20 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
" \n #### 发送时间:{}", " \n #### 发送时间:{}",
contract.getContractNo(), contract.getName(), applicantName, DateUtil.now()); contract.getContractNo(), contract.getName(), applicantName, DateUtil.now());
content.set("markdown", markdown); content.set("markdown", markdown);
content.set("btn_orientation", "1");
JSONArray jsonArray = new JSONArray();
// todo 暂无查看详情,需前端提供一个页面
// jsonArray.add(new JSONObject().set("title", "查看详情").set("action_url", "https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=dingkrzwks0jpi2di3uo&response_type=code&scope=snsapi_auth&state=STATE&redirect_uri=https%3A%2F%2Fyunwei.vionyun.com%3A8443%2Fyunwei%2Fapi%2Fding%2Fcallback%2Finside%3FtaskTempId%3D" + taskTemp.getId()));
content.set("btn_json_list", jsonArray);
msg.set("msgtype", "action_card"); msg.set("msgtype", "action_card");
msg.set("action_card", content); msg.set("action_card", content);
jsonObj.set("msg", msg); jsonObj.set("msg", msg);
return jsonObj; return jsonObj;
} }
private static class Result {
public final Set<String> roleCodeList;
public final MPJLambdaWrapper<Contract> wrapper;
public Result(Set<String> roleCodeList, MPJLambdaWrapper<Contract> wrapper) {
this.roleCodeList = roleCodeList;
this.wrapper = wrapper;
}
}
} }
\ No newline at end of file \ No newline at end of file
...@@ -4,7 +4,6 @@ import cn.dev33.satoken.stp.StpUtil; ...@@ -4,7 +4,6 @@ import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Opt; import cn.hutool.core.lang.Opt;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil; import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
...@@ -28,7 +27,6 @@ import vion.vo.UserVO; ...@@ -28,7 +27,6 @@ import vion.vo.UserVO;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -68,55 +66,10 @@ public class SettlementDiffServiceImpl extends MPJBaseServiceImpl<SettlementDiff ...@@ -68,55 +66,10 @@ public class SettlementDiffServiceImpl extends MPJBaseServiceImpl<SettlementDiff
public String save(SettlementDiffDTO dto) { public String save(SettlementDiffDTO dto) {
SettlementDiff settlementDiff = converter.convert(dto, SettlementDiff.class); SettlementDiff settlementDiff = converter.convert(dto, SettlementDiff.class);
if (this.save(settlementDiff)) { if (this.save(settlementDiff)) {
BigDecimal diffAmount = settlementDiff.getSettlementDiff(); calMoney(settlementDiff);
// 余额 = 总合同额 - 已收 + 差异 Long id = settlementDiff.getId();
// 应收 = 总合同额 * 比例 + 差异 (冲抵项为应收) handleFile(dto, id);
// = (总合同额 + 差异) * 比例 (冲抵项为合同额)
Contract existContract = contractService.lambdaQuery().eq(Contract::getContractNo, settlementDiff.getContractNo()).one();
if (settlementDiff.getOffsetItem() == 1) {
existContract.setTotalAmount(NumberUtil.add(existContract.getTotalAmount(), diffAmount));
Contract contractDto = new Contract();
contractDto.setId(existContract.getId());
contractPaymentService.calMoney(existContract, contractDto);
contractService.updateById(contractDto);
} else if (settlementDiff.getOffsetItem() == 2) {
Contract contractDto = new Contract();
contractDto.setId(existContract.getId());
contractDto.setReceivableAmount(NumberUtil.add(existContract.getReceivableAmount(), diffAmount));
contractDto.setOutstandingAmount(NumberUtil.add(existContract.getOutstandingAmount(), diffAmount));
contractService.updateById(contractDto);
}
Opt.ofNullable(dto.getFiles())
.ifPresent(fileList -> {
UserVO userVO = (UserVO) StpUtil.getTokenSession().get("curLoginUser");
Arrays.stream(fileList).forEach(infile -> {
String orgName = infile.getOriginalFilename();
String mainName = FileUtil.mainName(orgName);
String fileExt = FileUtil.extName(orgName);
String filename = StrUtil.format("{}_{}.{}", mainName, DateUtil.format(new Date(), "yyyyMMdd_HHmmss"), fileExt);;
String path = fileUrl + FileUtil.FILE_SEPARATOR + "settlementDiff" + FileUtil.FILE_SEPARATOR + dto.getContractNo() + FileUtil.FILE_SEPARATOR + filename;
File file = FileUtil.touch(path);
try {
infile.transferTo(file);
} catch (IOException e) {
log.error("保存文件出错", e);
}
FileInfo fileInfo = new FileInfo();
fileInfo.setStoreId(0L);
fileInfo.setSourceId(settlementDiff.getId());
fileInfo.setContractId(dto.getContractId());
fileInfo.setSourceType(15);
fileInfo.setName(filename);
fileInfo.setUrl(path);
fileInfo.setType(FileUtil.extName(file));
fileInfo.setSha256(SecureUtil.sha256(file).toUpperCase());
fileInfo.setUploader(userVO.getUsername());
fileService.save(fileInfo);
});
});
return "新增成功"; return "新增成功";
} }
return "新增失败"; return "新增失败";
...@@ -128,58 +81,70 @@ public class SettlementDiffServiceImpl extends MPJBaseServiceImpl<SettlementDiff ...@@ -128,58 +81,70 @@ public class SettlementDiffServiceImpl extends MPJBaseServiceImpl<SettlementDiff
SettlementDiff settlementDiff = converter.convert(dto, SettlementDiff.class); SettlementDiff settlementDiff = converter.convert(dto, SettlementDiff.class);
if (this.updateById(settlementDiff)) { if (this.updateById(settlementDiff)) {
SettlementDiff existDiff = this.getById(id); SettlementDiff existDiff = this.getById(id);
BigDecimal diffAmount = existDiff.getSettlementDiff(); calMoney(existDiff);
handleFile(dto, id);
// 余额 = 总合同额 - 已收 + 差异
// 应收 = 总合同额 * 比例 + 差异 (冲抵项为应收)
// = (总合同额 + 差异) * 比例 (冲抵项为合同额)
Contract existContract = contractService.lambdaQuery().eq(Contract::getContractNo, existDiff.getContractNo()).one();
if (existDiff.getOffsetItem() == 1) {
existContract.setTotalAmount(NumberUtil.add(existContract.getTotalAmount(), diffAmount));
Contract contractDto = new Contract();
contractDto.setId(existContract.getId());
contractPaymentService.calMoney(existContract, contractDto);
contractService.updateById(contractDto);
} else if (existDiff.getOffsetItem() == 2) {
Contract contractDto = new Contract();
contractDto.setId(existContract.getId());
contractDto.setReceivableAmount(NumberUtil.add(existContract.getReceivableAmount(), diffAmount));
contractDto.setOutstandingAmount(NumberUtil.add(existContract.getOutstandingAmount(), diffAmount));
contractService.updateById(contractDto);
}
Opt.ofNullable(dto.getFiles())
.ifPresent(fileList -> {
UserVO userVO = (UserVO) StpUtil.getTokenSession().get("curLoginUser");
Arrays.stream(fileList).forEach(infile -> {
String orgName = infile.getOriginalFilename();
String mainName = FileUtil.mainName(orgName);
String fileExt = FileUtil.extName(orgName);
String filename = StrUtil.format("{}_{}.{}", mainName, DateUtil.format(new Date(), "yyyyMMdd_HHmmss"), fileExt);;
String path = fileUrl + FileUtil.FILE_SEPARATOR + "settlementDiff" + FileUtil.FILE_SEPARATOR + dto.getContractNo() + FileUtil.FILE_SEPARATOR + filename;
File file = FileUtil.touch(path);
try {
infile.transferTo(file);
} catch (IOException e) {
log.error("保存文件出错", e);
}
FileInfo fileInfo = new FileInfo();
fileInfo.setStoreId(0L);
fileInfo.setSourceId(id);
fileInfo.setContractId(dto.getContractId());
fileInfo.setSourceType(15);
fileInfo.setName(filename);
fileInfo.setUrl(path);
fileInfo.setType(FileUtil.extName(file));
fileInfo.setSha256(SecureUtil.sha256(file).toUpperCase());
fileInfo.setUploader(userVO.getUsername());
fileService.save(fileInfo);
});
});
return "更新成功"; return "更新成功";
} }
return "更新失败"; return "更新失败";
} }
@Override
@Transactional(rollbackFor = Exception.class)
public String delById(Long id) {
Opt.ofEmptyAble(fileService.lambdaQuery()
.eq(FileInfo::getSourceId, id)
.eq(FileInfo::getSourceType, 15)
.list())
.ifPresent(l -> {
l.forEach(f -> FileUtil.del(f.getUrl()));
fileService.removeByIds(l);
});
SettlementDiff existDiff = this.getById(id);
this.removeById(id);
calMoney(existDiff);
return "删除成功";
}
private void calMoney(SettlementDiff existDiff) {
Contract existContract = contractService.lambdaQuery().eq(Contract::getContractNo, existDiff.getContractNo()).one();
Contract contractDto = new Contract();
contractDto.setId(existContract.getId());
contractPaymentService.calMoney(existContract, contractDto);
contractService.updateById(contractDto);
}
private void handleFile(SettlementDiffDTO dto, Long id) {
Opt.ofNullable(dto.getFiles())
.ifPresent(fileList -> {
UserVO userVO = (UserVO) StpUtil.getTokenSession().get("curLoginUser");
Arrays.stream(fileList).forEach(infile -> {
String orgName = infile.getOriginalFilename();
String mainName = FileUtil.mainName(orgName);
String fileExt = FileUtil.extName(orgName);
String filename = StrUtil.format("{}_{}.{}", mainName, DateUtil.format(new Date(), "yyyyMMdd_HHmmss"), fileExt);
String path = fileUrl + FileUtil.FILE_SEPARATOR + "settlementDiff" + FileUtil.FILE_SEPARATOR + dto.getContractNo() + FileUtil.FILE_SEPARATOR + filename;
File file = FileUtil.touch(path);
try {
infile.transferTo(file);
} catch (IOException e) {
log.error("保存文件出错", e);
}
FileInfo fileInfo = new FileInfo();
fileInfo.setStoreId(0L);
fileInfo.setSourceId(id);
fileInfo.setContractId(dto.getContractId());
fileInfo.setSourceType(15);
fileInfo.setName(filename);
fileInfo.setUrl(path);
fileInfo.setType(FileUtil.extName(file));
fileInfo.setSha256(SecureUtil.sha256(file).toUpperCase());
fileInfo.setUploader(userVO.getUsername());
fileService.save(fileInfo);
});
});
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!