InvChannelsExternalBillsDetailsController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. package com.ydtech.modules.inv.controller;
  2. import cn.dev33.satoken.stp.StpUtil;
  3. import cn.hutool.core.bean.BeanUtil;
  4. import cn.hutool.core.bean.copier.CopyOptions;
  5. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  6. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  7. import com.baomidou.mybatisplus.core.metadata.IPage;
  8. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  9. import com.ydtech.constants.enums.dict.finance.CheckingStatusEnum;
  10. import com.ydtech.core.page.HttpResult;
  11. import com.ydtech.core.page.PageResult;
  12. import com.ydtech.modules.admin.model.SysUser;
  13. import com.ydtech.modules.base.controller.BaseController;
  14. import com.ydtech.modules.base.model.dto.PageDto;
  15. import com.ydtech.modules.base.model.vo.PageVo;
  16. import com.ydtech.modules.inv.model.InvChannelsExternalBillsDetails;
  17. import com.ydtech.modules.inv.model.InvChannelsExternalBillsDetailsHistory;
  18. import com.ydtech.modules.inv.model.InvInsExternalBillsDetails;
  19. import com.ydtech.modules.inv.model.dto.InvInsCompanyDto;
  20. import com.ydtech.modules.inv.service.InvChannelsExternalBillsDetailsHistoryService;
  21. import com.ydtech.modules.inv.service.InvChannelsExternalBillsDetailsService;
  22. import com.ydtech.modules.inv.service.InvInsExternalBillsDetailsService;
  23. import com.ydtech.utils.StringUtils;
  24. import io.swagger.annotations.Api;
  25. import io.swagger.annotations.ApiImplicitParam;
  26. import io.swagger.annotations.ApiImplicitParams;
  27. import io.swagger.annotations.ApiOperation;
  28. import lombok.extern.slf4j.Slf4j;
  29. import org.springframework.transaction.annotation.Transactional;
  30. import org.springframework.web.bind.annotation.*;
  31. import org.springframework.web.multipart.MultipartFile;
  32. import javax.annotation.Resource;
  33. import java.util.ArrayList;
  34. import java.util.Date;
  35. import java.util.List;
  36. import java.util.function.Function;
  37. /**
  38. * 财务 - 渠道 - 外部票据控制层 详情
  39. *
  40. * @author: lig
  41. * @date: 2023-05-31
  42. */
  43. @Api(tags = "财务 - 渠道 - 外部票据 详情 控制层")
  44. @RestController
  45. @RequestMapping("api/inv/channelsExternalBillsDetails")
  46. @Slf4j
  47. public class InvChannelsExternalBillsDetailsController extends BaseController {
  48. //渠道
  49. @Resource
  50. private InvChannelsExternalBillsDetailsService icebdService;
  51. //渠道 历史
  52. @Resource
  53. private InvChannelsExternalBillsDetailsHistoryService icebdhService;
  54. //保险公司
  55. @Resource
  56. private InvInsExternalBillsDetailsService InvInsExternalBillsDetailsService;
  57. /**
  58. * 分页查询
  59. *
  60. * @param pageDto
  61. * @return
  62. */
  63. @ApiOperation(value = "分页查询")
  64. @PostMapping(value = "/queryPage")
  65. public HttpResult<PageResult<InvChannelsExternalBillsDetails>> queryPage(@RequestBody PageDto<InvInsCompanyDto> pageDto) {
  66. // public HttpResult<PageResult<InvChannelsExternalBillsDetails>> queryPage(@RequestBody InvInsExternalBillsDetailsReqVO reqVo) {
  67. LambdaQueryWrapper<InvChannelsExternalBillsDetails> lqw = new LambdaQueryWrapper();
  68. if(null != pageDto.getDto()){
  69. lqw.in(null != pageDto.getDto().getInsCompanyIds() && pageDto.getDto().getInsCompanyIds().size() > 0, InvChannelsExternalBillsDetails::getInsCompanyId, pageDto.getDto().getInsCompanyIds());
  70. lqw.eq(null != pageDto.getDto().getPayDate(),InvChannelsExternalBillsDetails::getPayDate,pageDto.getDto().getPayDate());
  71. lqw.eq(StringUtils.isNotEmpty(pageDto.getDto().getPlateNum()), InvChannelsExternalBillsDetails::getPlateNum, pageDto.getDto().getPlateNum());
  72. lqw.eq(StringUtils.isNotEmpty(pageDto.getDto().getOutChannel()), InvChannelsExternalBillsDetails::getOutChannel, pageDto.getDto().getOutChannel());
  73. lqw.eq(StringUtils.isNotEmpty(pageDto.getDto().getChannel()), InvChannelsExternalBillsDetails::getChannel, pageDto.getDto().getChannel());
  74. lqw.eq(StringUtils.isNotEmpty(pageDto.getDto().getStatus()), InvChannelsExternalBillsDetails::getStatus, pageDto.getDto().getStatus());
  75. }
  76. Page p = PageVo.buildPageRequest(pageDto);
  77. IPage<InvChannelsExternalBillsDetails> pResult = icebdService.page(p, lqw);
  78. //传入查询条件
  79. PageResult pageResult = PageResult.buildPageResult(pResult);
  80. return HttpResult.ok(pageResult);
  81. }
  82. @GetMapping("/detailsById")
  83. @ApiOperation(value = "详情")
  84. public HttpResult detailsById(String id) {
  85. return HttpResult.ok(icebdService.getById(id));
  86. }
  87. @ApiOperation(value = "修改")
  88. @PostMapping(value = "/edit")
  89. @Transactional
  90. public HttpResult edit(@RequestBody InvChannelsExternalBillsDetails icebd) {
  91. List<InvChannelsExternalBillsDetailsHistory> list = icebdhService.gainListByEditId(icebd.getId());
  92. List<InvChannelsExternalBillsDetailsHistory> icebdhList = new ArrayList<>();
  93. InvChannelsExternalBillsDetails icebdOld = icebdService.getById(icebd.getId());
  94. if (null == list || list.size() < 1) {
  95. //初始历史数据
  96. InvChannelsExternalBillsDetailsHistory icebdh = new InvChannelsExternalBillsDetailsHistory();
  97. // BeanUtils.copyProperties(icebdOld, icebdh,"id");
  98. BeanUtil.copyProperties(icebdOld, icebdh, CopyOptions.create(null, true, "id"));
  99. icebdh.setEditId(icebd.getId());
  100. icebdhList.add(icebdh);
  101. }
  102. InvChannelsExternalBillsDetailsHistory icebdh = new InvChannelsExternalBillsDetailsHistory();
  103. //构造更新数据
  104. BeanUtil.copyProperties(icebd, icebdOld, CopyOptions.create(null, true));
  105. //构造历史数据
  106. BeanUtil.copyProperties(icebdOld, icebdh, CopyOptions.create(null, true, "id"));
  107. // //构造更新数据
  108. // BeanUtils.copyProperties(icebdOld , icebd);
  109. // //构造历史数据
  110. // BeanUtils.copyProperties(icebd, icebdh,"id");
  111. icebdh.setEditId(icebdOld.getId());
  112. icebdh.setEditTime(new Date());
  113. icebdh.setEditBy(StpUtil.getLoginId().toString());
  114. icebdhList.add(icebdh);
  115. // icebdhService.saveBatch(icebdhList);
  116. icebdService.updateById(icebdOld);
  117. return HttpResult.ok(icebdhService.saveBatch(icebdhList));
  118. }
  119. @PostMapping(value = "/batchReceive")
  120. @ApiOperation(value = "批量领取")
  121. @ApiImplicitParams({
  122. @ApiImplicitParam(name = "ids", value = "渠道ID数组", dataType = "String", paramType = "body", allowMultiple = true, required = true)
  123. })
  124. public HttpResult batchReceive(@RequestBody List<String> ids) {
  125. LambdaQueryWrapper<InvChannelsExternalBillsDetails> lqw = new LambdaQueryWrapper<>();
  126. lqw.select(InvChannelsExternalBillsDetails::getPlateNum);
  127. lqw.in(InvChannelsExternalBillsDetails::getId,ids);
  128. //车牌号
  129. List<String> plateNums = icebdService.listObjs(lqw, new Function<Object, String>() {
  130. @Override
  131. public String apply(Object id) {
  132. return id.toString();
  133. }
  134. });
  135. //保险公司 更新状态
  136. LambdaUpdateWrapper<InvInsExternalBillsDetails> insLuw = new LambdaUpdateWrapper<>();
  137. insLuw.set(InvInsExternalBillsDetails::getStatus,CheckingStatusEnum.AS1.getCode());
  138. insLuw.in(InvInsExternalBillsDetails::getPlateNum,plateNums);
  139. insLuw.eq(InvInsExternalBillsDetails::getStatus,CheckingStatusEnum.AS0.getCode());
  140. InvInsExternalBillsDetailsService.update(insLuw);
  141. //渠道 更新批次号状态
  142. LambdaUpdateWrapper<InvChannelsExternalBillsDetails> luw = new LambdaUpdateWrapper<>();
  143. luw.set(InvChannelsExternalBillsDetails::getStatus, CheckingStatusEnum.AS1.getCode());
  144. luw.in(InvChannelsExternalBillsDetails::getId,ids);
  145. icebdService.update(luw);
  146. return HttpResult.ok("领取成功");
  147. }
  148. // @GetMapping(value = "/receive/{batchNum}")
  149. // @ApiOperation(value = "确认领取")
  150. // @ApiImplicitParams({
  151. // @ApiImplicitParam(name = "batchNum", value = "批次号", required = true, dataType = "String")
  152. // })
  153. // @Transactional
  154. // public HttpResult receive(@PathVariable String batchNum) {
  155. //
  156. // LambdaQueryWrapper<InvChannelsExternalBillsDetails> lqw = new LambdaQueryWrapper<>();
  157. // lqw.select(InvChannelsExternalBillsDetails::getPlateNum);
  158. // lqw.eq(InvChannelsExternalBillsDetails::getBatchNum,batchNum);
  159. //// List<InvChannelsExternalBillsDetails> iebdList = icebdService.list(lqw);
  160. // //车牌号
  161. // List<String> plateNums = icebdService.listObjs(lqw, new Function<Object, String>() {
  162. // @Override
  163. // public String apply(Object id) {
  164. // return id.toString();
  165. // }
  166. // });
  167. //
  168. // //保险公司 更新状态
  169. // LambdaUpdateWrapper<InvInsExternalBillsDetails> insLuw = new LambdaUpdateWrapper<>();
  170. // insLuw.set(InvInsExternalBillsDetails::getStatus,"1");
  171. // insLuw.in(InvInsExternalBillsDetails::getPlateNum,plateNums);
  172. // InvInsExternalBillsDetailsService.update(insLuw);
  173. //
  174. //
  175. //
  176. //
  177. // //渠道 更新批次号状态
  178. // LambdaUpdateWrapper<InvChannelsExternalBillsDetails> luw = new LambdaUpdateWrapper<>();
  179. // luw.set(InvChannelsExternalBillsDetails::getStatus,"1");
  180. // luw.eq(InvChannelsExternalBillsDetails::getBatchNum,batchNum);
  181. // icebdService.update(luw);
  182. //
  183. // return HttpResult.ok("领取成功");
  184. // }
  185. @PostMapping(value = "/batchPay")
  186. @ApiOperation(value = "批量支付")
  187. @ApiImplicitParams({
  188. @ApiImplicitParam(name = "ids", value = "渠道数据ID数组", dataType = "String", paramType = "body", allowMultiple = true, required = true)
  189. })
  190. public HttpResult pay(@RequestBody List<String> ids) {
  191. SysUser user = getUser();
  192. icebdService.pay(ids,user);
  193. return HttpResult.ok("支付成功");
  194. }
  195. @PostMapping(value = "/pay/{id}")
  196. @ApiOperation(value = "支付")
  197. @ApiImplicitParams({
  198. @ApiImplicitParam(name = "id", value = "渠道数据ID", dataType = "String", paramType = "path", required = true)
  199. })
  200. public HttpResult pay(@PathVariable String id) {
  201. SysUser user = getUser();
  202. List<String> ids = new ArrayList<>();
  203. ids.add(id);
  204. icebdService.pay(ids,user);
  205. return HttpResult.ok("支付成功");
  206. }
  207. @PostMapping("/importData")
  208. @ApiOperation(value = "渠道数据导入(excel)")
  209. @ApiImplicitParams({
  210. @ApiImplicitParam(name = "file", value = "excel文件", required = true, dataType = "__file")
  211. })
  212. public HttpResult importData(@RequestPart MultipartFile file) {
  213. icebdService.importData(file);
  214. return HttpResult.ok("导入成功");
  215. }
  216. @PostMapping(value = "/findEditHistory")
  217. @ApiOperation(value = "获取渠道修改历史")
  218. public HttpResult<PageResult<InvChannelsExternalBillsDetailsHistory>> findEditHistory(@RequestBody PageDto<InvInsCompanyDto> pageDto) {
  219. LambdaQueryWrapper<InvChannelsExternalBillsDetailsHistory> lqw = new LambdaQueryWrapper<>();
  220. if(null != pageDto.getDto()){
  221. lqw.eq(StringUtils.isNotEmpty(pageDto.getDto().getPlateNum()),InvChannelsExternalBillsDetailsHistory::getPlateNum,pageDto.getDto().getPlateNum());
  222. }
  223. lqw.orderByAsc(InvChannelsExternalBillsDetailsHistory::getPlateNum,InvChannelsExternalBillsDetailsHistory::getEditTime);
  224. Page p = PageVo.buildPageRequest(pageDto);
  225. IPage<InvChannelsExternalBillsDetailsHistory> pResult = icebdhService.page(p,lqw);
  226. //传入查询条件
  227. PageResult pageResult = PageResult.buildPageResult(pResult);
  228. return HttpResult.ok(pageResult);
  229. // return HttpResult.ok(sysUserService.gainUserPage(pageDto));
  230. }
  231. }