PaymentChannelController.java 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. package com.txz.cif.web.mng;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import com.txz.cif.core.AuthService;
  4. import com.txz.cif.core.Result;
  5. import com.txz.cif.core.ResultGenerator;
  6. import com.txz.cif.model.MidChannelMethod;
  7. import com.txz.cif.model.PaymentChannel;
  8. import com.txz.cif.model.PaymentMethod;
  9. import com.txz.cif.model.User;
  10. import com.txz.cif.service.MidChannelMethodService;
  11. import com.txz.cif.service.PaymentChannelService;
  12. import com.txz.cif.core.ResultCode;
  13. import com.github.pagehelper.PageHelper;
  14. import com.github.pagehelper.PageInfo;
  15. import com.txz.cif.service.PaymentMethodService;
  16. import com.txz.cif.service.UserService;
  17. import com.txz.cif.web.bo.PaymentChannelBO;
  18. import com.txz.cif.web.para.PaymentChannelParam;
  19. import com.txz.cif.web.para.updateparam.PaymentChannelUpdateParam;
  20. import org.springframework.util.CollectionUtils;
  21. import org.springframework.web.bind.annotation.*;
  22. import org.slf4j.Logger;
  23. import org.slf4j.LoggerFactory;
  24. import com.txz.core.ServiceException;
  25. import io.swagger.annotations.Api;
  26. import io.swagger.annotations.ApiOperation;
  27. import tk.mybatis.mapper.entity.Condition;
  28. import tk.mybatis.mapper.entity.Example.Criteria;
  29. import javax.annotation.Resource;
  30. import javax.servlet.http.HttpServletRequest;
  31. import java.util.ArrayList;
  32. import java.util.List;
  33. import java.util.stream.Collectors;
  34. /**
  35. * Created by CodeGenerator on 2025/08/04.
  36. */
  37. @Api(tags = "[后台]paymentChannel管理")
  38. @RestController
  39. @RequestMapping("/payment/channel")
  40. public class PaymentChannelController {
  41. private static Logger log = LoggerFactory.getLogger(PaymentChannelController.class);
  42. @Resource
  43. private PaymentChannelService paymentChannelService;
  44. @Resource
  45. private UserService userService;
  46. @Resource
  47. private AuthService authService;
  48. @PostMapping("/add")
  49. @ApiOperation(value = "支付通道新增",httpMethod = "POST")
  50. public Result add(@RequestBody PaymentChannelParam paymentChannelParam,HttpServletRequest request) {
  51. if(paymentChannelParam == null){
  52. return ResultGenerator.genFailResult(ResultCode.OBJECT_IS_NULL);
  53. }
  54. // Long userId = authService.getTokenUserId(request);
  55. // if (userId == null ){
  56. // ResultGenerator.genFailResult(ResultCode.USERID_IS_NULL);
  57. // }
  58. // User user = userService.findById(userId);
  59. // if (user == null ){
  60. // ResultGenerator.genFailResult(ResultCode.USER_IS_NULL);
  61. // }
  62. try {
  63. // paymentChannel.setCreateTime(new Date());
  64. // paymentChannel.setCreateUserId(userId);
  65. PaymentChannel bean = BeanUtil.toBean(paymentChannelParam, PaymentChannel.class);
  66. bean.setIsValid((byte)1);
  67. bean.setVersion(1);
  68. bean.setCreateUser("lala");
  69. bean.setUpdateUser("lala");
  70. paymentChannelService.add(bean);
  71. } catch (Exception e) {
  72. log.error("新增对象操作异常e:{}",e);
  73. return ResultGenerator.genFailResult(ResultCode.INTERNAL_SERVER_ERROR);
  74. }
  75. return ResultGenerator.genSuccessResult();
  76. }
  77. // @GetMapping("/delete")
  78. // @ApiOperation(value = "paymentChannel删除",httpMethod = "GET")
  79. // public Result delete(@RequestParam Integer id) {
  80. // if(id == null){
  81. // return ResultGenerator.genFailResult(ResultCode.ID_IS_NULL);
  82. // }
  83. // try {
  84. // paymentChannelService.deleteById(id);
  85. // } catch (Exception e) {
  86. // log.error("删除对象操作异常e:{}",e);
  87. // return ResultGenerator.genFailResult(ResultCode.INTERNAL_SERVER_ERROR);
  88. // }
  89. // return ResultGenerator.genSuccessResult();
  90. // }
  91. @PostMapping("/update")
  92. @ApiOperation(value = "paymentChannel更新",httpMethod = "POST")
  93. public Result update(@RequestBody PaymentChannelUpdateParam paymentChannelUpdateParam) {
  94. if(paymentChannelUpdateParam == null){
  95. return ResultGenerator.genFailResult(ResultCode.OBJECT_IS_NULL);
  96. }
  97. if(paymentChannelUpdateParam.getId() == null){
  98. return ResultGenerator.genFailResult(ResultCode.ID_IS_NULL);
  99. }
  100. PaymentChannel bean = BeanUtil.toBean(paymentChannelUpdateParam, PaymentChannel.class);
  101. try {
  102. // paymentChannel.setUpdateTime(new Date());
  103. // paymentChannel.setUpdateUserId(userId);
  104. paymentChannelService.modify(bean);
  105. } catch (Exception e) {
  106. log.error("更新对象操作异常e:{}",e);
  107. return ResultGenerator.genFailResult(ResultCode.INTERNAL_SERVER_ERROR);
  108. }
  109. return ResultGenerator.genSuccessResult();
  110. }
  111. // @GetMapping("/detail")
  112. // @ApiOperation(value = "paymentChannel获取详情",httpMethod = "GET")
  113. // public Result<PaymentChannel> detail(@RequestParam Integer id) {
  114. // if(id == null){
  115. // return ResultGenerator.genFailResult(ResultCode.ID_IS_NULL);
  116. // }
  117. //
  118. // PaymentChannel paymentChannel = null;
  119. // try {
  120. // paymentChannel = paymentChannelService.findById(id);
  121. // } catch (Exception e) {
  122. // log.error("查询对象操作异常e:{}",e);
  123. // return ResultGenerator.genFailResult(ResultCode.INTERNAL_SERVER_ERROR);
  124. // }
  125. //
  126. // return ResultGenerator.genSuccessResult(paymentChannel);
  127. // }
  128. @PostMapping("/list")
  129. @ApiOperation(value = "paymentChannel获取列表",httpMethod = "POST")
  130. public Result<List<PaymentChannelBO>> list() {
  131. // PageHelper.startPage(page, size);
  132. //
  133. // Condition condition = new Condition(paymentChannel.getClass());
  134. // Criteria criteria = condition.createCriteria();
  135. // criteria.andEqualTo("name", city.getName());
  136. // PageInfo pageInfo = null;
  137. List<PaymentChannelBO> resultList = new ArrayList<>();
  138. Byte b = (byte) 1;
  139. try {
  140. List<PaymentChannel> list = paymentChannelService.findAll();
  141. if(!CollectionUtils.isEmpty(list)) {
  142. resultList = list.stream().filter(a -> b.equals(a.getIsValid())).map(a -> BeanUtil.toBean(a, PaymentChannelBO.class)).collect(Collectors.toList());
  143. }
  144. } catch (Exception e) {
  145. log.error("查询对象操作异常e:{}",e);
  146. return ResultGenerator.genFailResult(ResultCode.INTERNAL_SERVER_ERROR);
  147. }
  148. return ResultGenerator.genSuccessResult(resultList);
  149. }
  150. }