UserChannelApiController.java 4.9 KB

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