CaseErpCustomerGatherController.java 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package com.xjrsoft.module.erpModel.caseErpCustomer.controller;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import cn.hutool.core.convert.Convert;
  4. import cn.hutool.core.lang.TypeReference;
  5. import cn.hutool.core.util.StrUtil;
  6. import com.baomidou.mybatisplus.core.toolkit.StringPool;
  7. import com.xjrsoft.common.annotation.XjrLog;
  8. import com.xjrsoft.common.constant.GlobalConstant;
  9. import com.xjrsoft.common.model.result.R;
  10. import com.xjrsoft.common.utils.RedisUtil;
  11. import com.xjrsoft.module.erpModel.caseErpCustomer.dto.AddCaseErpCustomerGatherDto;
  12. import com.xjrsoft.module.erpModel.caseErpCustomer.dto.CaseErpCustomerGatherDto;
  13. import com.xjrsoft.module.erpModel.caseErpCustomer.dto.UpdateCaseErpCustomerGatherDto;
  14. import com.xjrsoft.module.erpModel.caseErpCustomer.entity.CaseErpCustomer;
  15. import com.xjrsoft.module.erpModel.caseErpCustomer.entity.CaseErpCustomerGather;
  16. import com.xjrsoft.module.erpModel.caseErpCustomer.service.ICaseErpCustomerGatherService;
  17. import com.xjrsoft.module.erpModel.caseErpCustomer.service.ICaseErpCustomerService;
  18. import com.xjrsoft.module.organization.entity.User;
  19. import io.swagger.annotations.Api;
  20. import io.swagger.annotations.ApiOperation;
  21. import lombok.AllArgsConstructor;
  22. import org.springframework.web.bind.annotation.DeleteMapping;
  23. import org.springframework.web.bind.annotation.GetMapping;
  24. import org.springframework.web.bind.annotation.PostMapping;
  25. import org.springframework.web.bind.annotation.PutMapping;
  26. import org.springframework.web.bind.annotation.RequestBody;
  27. import org.springframework.web.bind.annotation.RequestMapping;
  28. import org.springframework.web.bind.annotation.RequestParam;
  29. import org.springframework.web.bind.annotation.RestController;
  30. import javax.validation.Valid;
  31. import java.math.BigDecimal;
  32. import java.util.Arrays;
  33. import java.util.List;
  34. import java.util.stream.Collectors;
  35. /**
  36. * <p>
  37. * 客户回款【case_erp_customer_gather】 前端控制器
  38. * </p>
  39. *
  40. * @author hnyyzy
  41. * @since 2023-07-12
  42. */
  43. @RestController
  44. @RequestMapping(GlobalConstant.CASE_ERP_CUSTOMER +"/caseErpCustomerGather")
  45. @Api(value = GlobalConstant.CASE_ERP_CUSTOMER +"/caseErpCustomerGather", tags = "客户回款")
  46. @AllArgsConstructor
  47. public class CaseErpCustomerGatherController {
  48. private ICaseErpCustomerGatherService caseErpCustomerGatherService;
  49. private ICaseErpCustomerService caseErpCustomerService;
  50. private RedisUtil redisUtil;
  51. @GetMapping(value = "/page")
  52. @ApiOperation("客户回款分页")
  53. public R page(CaseErpCustomerGatherDto dto) {
  54. return R.ok(caseErpCustomerGatherService.getPageList(dto));
  55. }
  56. @PostMapping
  57. @ApiOperation(value = "新增客户回款信息")
  58. public R add(@Valid @RequestBody AddCaseErpCustomerGatherDto dto) {
  59. CaseErpCustomerGather caseErpCustomerGather = BeanUtil.toBean(dto, CaseErpCustomerGather.class);
  60. CaseErpCustomer byId = caseErpCustomerService.getById(dto.getCustomerId());
  61. if (StrUtil.isNotBlank(byId.getName())){
  62. caseErpCustomerGather.setName(byId.getName());
  63. }
  64. caseErpCustomerGather.setAlreadyAmount(BigDecimal.ZERO);
  65. caseErpCustomerGather.setUnpaidAmount(dto.getWaitAmount());
  66. List<User> allUser = redisUtil.get(GlobalConstant.USER_CACHE_KEY, new TypeReference<List<User>>() {
  67. });
  68. String allUserIdStr = StrUtil.join(StringPool.COMMA, dto.getPrincipalIds());
  69. List<Long> ids = Arrays.stream(allUserIdStr.split(StringPool.COMMA)).map(Convert::toLong).collect(Collectors.toList());
  70. List<String> names = allUser.stream().filter(x -> ids.contains(x.getId())).map(User::getName).collect(Collectors.toList());
  71. caseErpCustomerGather.setPrincipalNames(StrUtil.join(StringPool.COMMA,names));
  72. caseErpCustomerGatherService.save(caseErpCustomerGather);
  73. return R.ok(true);
  74. }
  75. @PutMapping
  76. @ApiOperation(value = "修改客户回款信息")
  77. public R update(@Valid @RequestBody UpdateCaseErpCustomerGatherDto dto) {
  78. CaseErpCustomerGather caseErpCustomerGather = BeanUtil.toBean(dto, CaseErpCustomerGather.class);
  79. CaseErpCustomer byId = caseErpCustomerService.getById(dto.getCustomerId());
  80. if (StrUtil.isNotBlank(byId.getName())){
  81. caseErpCustomerGather.setName(byId.getName());
  82. }
  83. List<User> allUser = redisUtil.get(GlobalConstant.USER_CACHE_KEY, new TypeReference<List<User>>() {
  84. });
  85. String allUserIdStr = StrUtil.join(StringPool.COMMA, dto.getPrincipalIds());
  86. List<Long> ids = Arrays.stream(allUserIdStr.split(StringPool.COMMA)).map(Convert::toLong).collect(Collectors.toList());
  87. List<String> names = allUser.stream().filter(x -> ids.contains(x.getId())).map(User::getName).collect(Collectors.toList());
  88. caseErpCustomerGather.setPrincipalNames(StrUtil.join(StringPool.COMMA,names));
  89. return R.ok(caseErpCustomerGatherService.updateById(caseErpCustomerGather));
  90. }
  91. @GetMapping(value = "/info")
  92. @ApiOperation(value = "根据id查询客户回款信息")
  93. public R info(@RequestParam Long id) {
  94. CaseErpCustomerGather caseErpCustomerGather = caseErpCustomerGatherService.getById(id);
  95. if (caseErpCustomerGather == null) {
  96. R.error("找不到此客户回款信息!");
  97. }
  98. return R.ok(caseErpCustomerGather);
  99. }
  100. @DeleteMapping
  101. @ApiOperation(value = "删除")
  102. @XjrLog(value = "删除客户回款信息")
  103. public R delete(@Valid @RequestBody Long id) {
  104. return R.ok(caseErpCustomerGatherService.removeById(id));
  105. }
  106. @GetMapping(value = "/gather-detail-info")
  107. @ApiOperation(value = "根据客户回款id查询客户回款记录信息")
  108. public R gatherDetailInfo(@RequestParam Long id) {
  109. return R.ok(caseErpCustomerGatherService.gatherDetailInfo(id));
  110. }
  111. }