AdminOrderReceivablesApiController.java 9.1 KB

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