UserChannelApiController.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. package com.goafanti.user.controller;
  2. import java.util.List;
  3. import javax.annotation.Resource;
  4. import javax.servlet.http.HttpServletRequest;
  5. import javax.servlet.http.HttpServletResponse;
  6. import org.springframework.web.bind.annotation.RequestMapping;
  7. import org.springframework.web.bind.annotation.RequestMethod;
  8. import org.springframework.web.bind.annotation.RequestParam;
  9. import org.springframework.web.bind.annotation.RestController;
  10. import org.springframework.web.multipart.MultipartFile;
  11. import com.goafanti.admin.service.AttachmentService;
  12. import com.goafanti.common.bo.Result;
  13. import com.goafanti.common.constant.ErrorConstants;
  14. import com.goafanti.common.controller.CertifyApiController;
  15. import com.goafanti.common.enums.AttachmentType;
  16. import com.goafanti.common.model.Attachment;
  17. import com.goafanti.common.utils.StringUtils;
  18. import com.goafanti.common.utils.excel.NewExcelUtil;
  19. import com.goafanti.user.bo.InputUserChannel;
  20. import com.goafanti.user.bo.OutUserChannel;
  21. import com.goafanti.user.service.UserChannelService;
  22. @RestController
  23. @RequestMapping(value = "/api/user/channel")
  24. public class UserChannelApiController extends CertifyApiController{
  25. @Resource
  26. private UserChannelService userChannelService;
  27. @Resource
  28. private AttachmentService attachmentService;
  29. /**
  30. * 新增渠道
  31. * @return
  32. */
  33. @RequestMapping(value = "/add", method = RequestMethod.POST)
  34. public Result add(InputUserChannel in) {
  35. Result res = new Result();
  36. if (StringUtils.isBlank(in.getUserName())) {
  37. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "用户名称"));
  38. return res;
  39. }
  40. res.setData(userChannelService.add(in));
  41. return res;
  42. }
  43. /**
  44. * 删除渠道
  45. * @return
  46. */
  47. @RequestMapping(value = "/delete", method = RequestMethod.POST)
  48. public Result delete(String ids) {
  49. Result res = new Result();
  50. if (StringUtils.isBlank(ids)) {
  51. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "编号"));
  52. return res;
  53. }
  54. res.setData(userChannelService.delete(ids));
  55. return res;
  56. }
  57. /**
  58. * Excel批量导入渠道客户
  59. * @return
  60. */
  61. @RequestMapping(value = "/import" , method = RequestMethod.POST)
  62. public Result importTemplate(@RequestParam(value = "file", required = false) MultipartFile file, HttpServletRequest request) {
  63. Result res=new Result();
  64. //判断文件是否存在
  65. if(null == file){
  66. res.getError().add(buildError("文件不存在!","文件不存在!"));
  67. return res;
  68. }
  69. String fileName = file.getOriginalFilename();
  70. if (!fileName.matches("^.+\\.(?i)(xls)$") && !fileName.matches("^.+\\.(?i)(xlsx)$")) {
  71. res.getError().add(buildError("格式不正确","格式不正确"));
  72. return res;
  73. }
  74. res.data(userChannelService.batchListReceivables(file));
  75. return res;
  76. }
  77. /**
  78. * 已存在渠道客户列表
  79. * @return
  80. */
  81. @RequestMapping(value = "/erorrList" , method = RequestMethod.GET)
  82. public Result erorrList(Integer pageNo,Integer pageSize) {
  83. Result res =new Result();
  84. res.data(userChannelService.getErorrList(pageNo,pageSize));
  85. return res;
  86. }
  87. /**
  88. * 导出已存在渠道客户
  89. * @param response
  90. * @return
  91. */
  92. @RequestMapping(value = "/export" , method = RequestMethod.GET)
  93. public Result exportReceivables(HttpServletResponse response) {
  94. @SuppressWarnings("unchecked")
  95. List<OutUserChannel> list =(List<OutUserChannel>) userChannelService.getErorrList(1,99999).getList();
  96. NewExcelUtil<OutUserChannel>excel=new NewExcelUtil<>(OutUserChannel.class);
  97. return excel.exportExcel(list,"未导入渠道客户表",response);
  98. }
  99. /**
  100. * 下载回款批量导入Excel模板
  101. * @param response
  102. * @return
  103. */
  104. @RequestMapping(value = "/downloadTemplate", method = RequestMethod.GET)
  105. public Result downloadTemplateFile(HttpServletResponse response, String sign) {
  106. Result res = new Result();
  107. AttachmentType attachmentType = AttachmentType.getField(sign);
  108. if (attachmentType == AttachmentType.USER_CHANNEL) {
  109. String fileName = "";
  110. Attachment af = attachmentService.selectByReceivbles(sign);
  111. if (null == af) {
  112. res.getError().add(buildError(ErrorConstants.FILE_NON_EXISTENT, "", "找不到文件!"));
  113. } else {
  114. String path = af.getFilePath();
  115. String suffix = path.substring(path.lastIndexOf("."));
  116. fileName = AttachmentType.USER_CHANNEL.getDesc() + suffix;
  117. downloadFile(response, fileName, path);
  118. }
  119. } else {
  120. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
  121. }
  122. return res;
  123. }
  124. }