AdminOrderReceivablesApiController.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. package com.goafanti.order.controller;
  2. import com.goafanti.admin.service.AttachmentService;
  3. import com.goafanti.common.bo.Error;
  4. import com.goafanti.common.bo.Result;
  5. import com.goafanti.common.constant.ErrorConstants;
  6. import com.goafanti.common.controller.CertifyApiController;
  7. import com.goafanti.common.enums.AttachmentType;
  8. import com.goafanti.common.error.BusinessException;
  9. import com.goafanti.common.model.Attachment;
  10. import com.goafanti.common.model.TOrderBillNew;
  11. import com.goafanti.common.utils.LoggerUtils;
  12. import com.goafanti.common.utils.excel.NewExcelUtil;
  13. import com.goafanti.core.mybatis.page.Pagination;
  14. import com.goafanti.order.bo.OrderListBo;
  15. import com.goafanti.order.bo.ReceivablesListBo;
  16. import com.goafanti.order.bo.TOrderInvoiceBo;
  17. import com.goafanti.order.bo.TemporaryReceivablesBo;
  18. import com.goafanti.order.enums.ApprovalTypeEnums;
  19. import com.goafanti.order.service.FundManageOrderService;
  20. import com.goafanti.order.service.OrderBillService;
  21. import com.goafanti.order.service.OrderInvoiceService;
  22. import com.goafanti.order.service.OrderReceivablesService;
  23. import org.apache.commons.lang3.StringUtils;
  24. import org.springframework.beans.factory.annotation.Value;
  25. import org.springframework.web.bind.annotation.RequestMapping;
  26. import org.springframework.web.bind.annotation.RequestMethod;
  27. import org.springframework.web.bind.annotation.RequestParam;
  28. import org.springframework.web.bind.annotation.RestController;
  29. import org.springframework.web.multipart.MultipartFile;
  30. import javax.annotation.Resource;
  31. import javax.servlet.http.HttpServletRequest;
  32. import javax.servlet.http.HttpServletResponse;
  33. import java.util.HashMap;
  34. import java.util.List;
  35. import java.util.Map;
  36. @RestController
  37. @RequestMapping(value = "/api/admin/receivables")
  38. public class AdminOrderReceivablesApiController extends CertifyApiController {
  39. @Resource
  40. private OrderReceivablesService orderReceivablesService;
  41. @Resource
  42. private AttachmentService attachmentService;
  43. @Resource
  44. private OrderBillService orderBillService;
  45. @Resource
  46. private OrderInvoiceService orderInvoiceService;
  47. @Resource
  48. private FundManageOrderService fundManageOrderService;
  49. @Value(value = "${upload.path}")
  50. private String uploadPath = null;
  51. /**
  52. * 新增预计回款信息
  53. * @param t
  54. * @return
  55. */
  56. @RequestMapping(value = "/addReceivables",method = RequestMethod.POST)
  57. public Result addReceivables(TemporaryReceivablesBo t){
  58. Result res = new Result();
  59. res=inputCheck(t, res);
  60. if (!res.getError().isEmpty()) {
  61. return res;
  62. }
  63. res.data(orderReceivablesService.addReceivables(t));
  64. return res;
  65. }
  66. private Result inputCheck(TemporaryReceivablesBo t, Result res) {
  67. if(StringUtils.isBlank(t.getOrderNo())){
  68. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"","订单编号编号"));
  69. return res;
  70. }
  71. if(t.getAmount() == null){
  72. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"","收款金额"));
  73. return res;
  74. }
  75. if(t.getReceivablesTimes() == null){
  76. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"","收款时间"));
  77. return res;
  78. }
  79. return res;
  80. }
  81. /**
  82. * 修改预计回款
  83. */
  84. @RequestMapping(value = "/updateReceivables",method = RequestMethod.POST)
  85. public Result updateReceivables(TemporaryReceivablesBo t){
  86. Result res = new Result();
  87. res=inputCheck(t, res);
  88. if (!res.getError().isEmpty()) {
  89. return res;
  90. }
  91. res.data(orderReceivablesService.updateReceivables(t));
  92. return res;
  93. }
  94. /**
  95. * 删除预计回款
  96. * @param ids 逗号隔开的id
  97. * @param type 0 多个 1全部
  98. * @return
  99. */
  100. @RequestMapping(value = "/deleteReceivables",method = RequestMethod.POST)
  101. public Result deleteReceivables(String ids,Integer type){
  102. Result res = new Result();
  103. if(type==null) {
  104. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"","删除类型"));
  105. return res;
  106. }else if (type==0) {
  107. if(null==ids) {
  108. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"","id或删除量"));
  109. return res;
  110. }
  111. res.data(orderReceivablesService.deleteReceivables(ids));
  112. } else {
  113. res.data(orderReceivablesService.deleteAllReceivables());
  114. }
  115. return res;
  116. }
  117. @RequestMapping(value ="/listReceivables",method = RequestMethod.GET)
  118. public Result listReceivables(ReceivablesListBo rl,Integer status,String adminName,String adminDeps,String orderDeps,
  119. Integer mergeStatus,Integer pageSize,Integer pageNo){
  120. Result res = new Result();
  121. Map<String, Object>map =new HashMap<>();
  122. //列表数据
  123. map.put("pagination", orderReceivablesService.listReceivables( rl,status,adminName, adminDeps, orderDeps,mergeStatus, pageSize, pageNo));
  124. //统计数据
  125. map.put("count",orderReceivablesService.getCountlistReceivables( rl,status,adminName, adminDeps, orderDeps,mergeStatus));
  126. res.data(map);
  127. return res;
  128. }
  129. /**
  130. * 处理批量导入(批量回款)
  131. *
  132. *
  133. */
  134. @RequestMapping(value ="/batchImport",method = RequestMethod.POST)
  135. public Result batchImport(Integer mergeStatus){
  136. LoggerUtils.debug(getClass(), "=========================开始批量导入===================");
  137. Result res = new Result();
  138. int i=0;
  139. i=orderReceivablesService.batchImport( mergeStatus);
  140. if (i==-1) {
  141. throw new BusinessException(new Error("未找到正确的回款信息。"));
  142. }
  143. return res;
  144. }
  145. /**
  146. * 下载回款批量导入Excel模板
  147. *
  148. * @param response
  149. * @return
  150. */
  151. @RequestMapping(value = "/downloadTemplate", method = RequestMethod.GET)
  152. public Result downloadTemplateFile(HttpServletResponse response, String sign) {
  153. Result res = new Result();
  154. AttachmentType attachmentType = AttachmentType.getField(sign);
  155. if (attachmentType == AttachmentType.RECEIVABLES_TEMPLATE) {
  156. String fileName = "";
  157. Attachment af = attachmentService.selectByReceivbles(sign);
  158. if (null == af) {
  159. res.getError().add(buildError(ErrorConstants.FILE_NON_EXISTENT, "", "找不到文件!"));
  160. } else {
  161. String path = af.getFilePath();
  162. String suffix = path.substring(path.lastIndexOf("."));
  163. fileName = AttachmentType.RECEIVABLES_TEMPLATE.getDesc() + suffix;
  164. downloadFile(response, fileName, path);
  165. }
  166. } else {
  167. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
  168. }
  169. return res;
  170. }
  171. /**
  172. * Excel批量导入回款
  173. *
  174. * @return
  175. */
  176. @RequestMapping(value = "/import" , method = RequestMethod.POST)
  177. public Result importTemplate(@RequestParam(value = "file", required = false) MultipartFile file, HttpServletRequest request) {
  178. Result res=new Result();
  179. //判断文件是否存在
  180. if(null == file){
  181. res.getError().add(buildError("文件不存在!","文件不存在!"));
  182. return res;
  183. }
  184. String fileName = file.getOriginalFilename();
  185. if (!fileName.matches("^.+\\.(?i)(xls)$") && !fileName.matches("^.+\\.(?i)(xlsx)$")) {
  186. res.getError().add(buildError("格式不正确","格式不正确"));
  187. return res;
  188. }
  189. orderReceivablesService.batchListReceivables(file);
  190. res.data(1);
  191. return res;
  192. }
  193. /**
  194. * 导出回款
  195. *
  196. * @return
  197. */
  198. @RequestMapping(value = "/exportReceivables" , method = RequestMethod.GET)
  199. public Result exportReceivables(OrderListBo o,Integer pageSize ,Integer pageNo) {
  200. if (pageSize==null)pageSize=99999;
  201. o.setOrderStatus(2);//营销管理员审核通过
  202. @SuppressWarnings("unchecked")
  203. Pagination<OrderListBo> p=(Pagination<OrderListBo>) fundManageOrderService.financeList(o, pageNo, pageSize).get("pagination");
  204. @SuppressWarnings("unchecked")
  205. List<OrderListBo> list=(List<OrderListBo>)p.getList() ;
  206. for (OrderListBo e : list) {
  207. if (e.getType()!=null){
  208. String[] split = e.getType().split(",");
  209. StringBuilder str=new StringBuilder();
  210. for (String s : split) {
  211. if (s.equals("0")){
  212. str.append(ApprovalTypeEnums.getDesc(s))
  213. .append("(").append(e.getTypeExplain()).append(")")
  214. .append(",");
  215. }else {
  216. String desc = ApprovalTypeEnums.getDesc(Integer.parseInt(s));
  217. str.append(desc).append(",");
  218. }
  219. }
  220. e.setType(str.substring(0,str.length()-1));
  221. }
  222. }
  223. NewExcelUtil<OrderListBo>excel=new NewExcelUtil<>(OrderListBo.class);
  224. return excel.exportExcel(list,"订单回款列表",uploadPath);
  225. }
  226. /**
  227. * 导出开票
  228. *
  229. * @param response
  230. * @return
  231. */
  232. @RequestMapping(value = "/exportInvoice" , method = RequestMethod.GET)
  233. public Result exportInvoice(HttpServletResponse response,String orderNo,Integer pageSize ,Integer pageNo) {
  234. if (pageSize==null)pageSize=99999;
  235. @SuppressWarnings("unchecked")
  236. List<TOrderInvoiceBo>list=(List<TOrderInvoiceBo>) orderInvoiceService.salesmanOrderInvoiceList( orderNo, pageNo,pageSize).getList();
  237. NewExcelUtil<TOrderInvoiceBo>excel=new NewExcelUtil<>(TOrderInvoiceBo.class);
  238. return excel.exportExcel(list,"订单"+orderNo+"开票列表",response);
  239. }
  240. /**
  241. * 导出流水
  242. *
  243. * @param response
  244. * @return
  245. */
  246. @RequestMapping(value = "/exportMyBill" , method = RequestMethod.GET)
  247. public Result exportMyBill(HttpServletResponse response, TOrderBillNew billNew,Integer pageSize ,Integer pageNo) {
  248. if (pageSize==null)pageSize=99999;
  249. @SuppressWarnings("unchecked")
  250. List<TOrderBillNew>list=(List<TOrderBillNew>) orderBillService.myBillList(billNew,pageNo, pageSize).getList();
  251. NewExcelUtil<TOrderBillNew>excel=new NewExcelUtil<>(TOrderBillNew.class);
  252. return excel.exportExcel(list,"订单流水列表",response);
  253. }
  254. @RequestMapping(value = "/waitingMerge",method = RequestMethod.POST)
  255. public Result waitingMerge(String ids){
  256. Result res=new Result();
  257. if (ids==null||ids.isEmpty()){
  258. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"回款编号"));
  259. return res;
  260. }
  261. res.data(orderReceivablesService.pushWaitingMerge(ids));
  262. return res;
  263. }
  264. /**
  265. * 匹配
  266. * @param value 匹配数据值
  267. * @return
  268. */
  269. @RequestMapping(value = "/matchingOrderNo",method = RequestMethod.GET)
  270. public Result matchingOrderNo(String value){
  271. Result res=new Result();
  272. if (value==null){
  273. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"数据值"));
  274. return res;
  275. }
  276. res.data(orderReceivablesService.matchingOrderNo(value));
  277. return res;
  278. }
  279. /**
  280. * 匹配
  281. * @param value 匹配数据值
  282. * @return
  283. */
  284. @RequestMapping(value = "/matchingUser",method = RequestMethod.GET)
  285. public Result matchingUser(String value){
  286. Result res=new Result();
  287. if (value==null){
  288. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"数据值"));
  289. return res;
  290. }
  291. res.data(orderReceivablesService.matchingUser(value));
  292. return res;
  293. }
  294. }