OrderBonusStatisticsApiController.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. package com.goafanti.order.controller;
  2. import java.io.IOException;
  3. import java.io.OutputStream;
  4. import java.text.SimpleDateFormat;
  5. import java.util.Date;
  6. import java.util.Set;
  7. import java.util.TreeSet;
  8. import javax.annotation.Resource;
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;
  11. import org.apache.poi.xssf.usermodel.XSSFCell;
  12. import org.apache.poi.xssf.usermodel.XSSFRow;
  13. import org.apache.poi.xssf.usermodel.XSSFSheet;
  14. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  15. import org.springframework.beans.factory.annotation.Value;
  16. import org.springframework.web.bind.annotation.RequestMapping;
  17. import org.springframework.web.bind.annotation.RequestMethod;
  18. import org.springframework.web.bind.annotation.RestController;
  19. import com.goafanti.common.bo.Error;
  20. import com.goafanti.common.bo.Result;
  21. import com.goafanti.common.controller.CertifyApiController;
  22. import com.goafanti.common.model.TOrderNew;
  23. import com.goafanti.common.utils.ExcelUtils;
  24. import com.goafanti.common.utils.ExportExcelUtil;
  25. import com.goafanti.common.utils.StringUtils;
  26. import com.goafanti.core.shiro.token.TokenManager;
  27. import com.goafanti.order.bo.OrderReportBo;
  28. import com.goafanti.order.bo.TOrderBonusBo;
  29. import com.goafanti.order.service.FundManageOrderService;
  30. import com.goafanti.order.service.OrderBonusService;
  31. import com.goafanti.order.service.OrderReportService;
  32. import com.goafanti.permission.service.NewRoleService;
  33. @RestController
  34. @RequestMapping(value = "/api/admin/bonus")
  35. public class OrderBonusStatisticsApiController extends CertifyApiController {
  36. @Resource
  37. private FundManageOrderService fundManageOrderServiceImpl;
  38. @Resource
  39. private OrderBonusService orderBonusServiceImpl;
  40. @Resource
  41. private OrderReportService orderReportServiceImpl;
  42. @Resource
  43. private NewRoleService newRoleService;
  44. @Value(value = "${upload.private.path}")
  45. private String uploadPrivatePath = null;
  46. /**
  47. * 财务专员校对单量
  48. * @param orderNew
  49. * @return
  50. */
  51. @RequestMapping(value="/proofreading", method = RequestMethod.POST)
  52. public Result proofreading(TOrderNew orderNew){
  53. Result res = new Result();
  54. res.setData(fundManageOrderServiceImpl.updateProofreading(orderNew));
  55. return res;
  56. }
  57. /**
  58. * 营销员奖金统计
  59. * @param orderNewBo
  60. * @return
  61. */
  62. @RequestMapping(value="/saleBonusStatistics", method = RequestMethod.GET)
  63. public Result saleBonusStatistics(TOrderBonusBo bonusBo, Integer pageNo, Integer pageSize){
  64. Result res = new Result();
  65. bonusBo.setGrantBy(TokenManager.getAdminId());
  66. res.setData(orderBonusServiceImpl.saleBonusStatistics(bonusBo, pageNo, pageSize));
  67. return res;
  68. }
  69. /**
  70. * 财务专员发放营销员奖金
  71. * @param id
  72. * @return
  73. */
  74. @RequestMapping(value="/bonusPayment", method = RequestMethod.POST)
  75. public Result bonusPayment(String id,String orderNo){
  76. Result res = new Result();
  77. Integer i = orderBonusServiceImpl.updateBounsPaymnetStatus(id, orderNo);
  78. if(i>0){
  79. res.setData("发放成功!");
  80. }else{
  81. res.getError().add(buildError("", "没有校对单量,不能发放"));
  82. }
  83. return res;
  84. }
  85. /**
  86. * 财务专员查看技术员奖金数据
  87. * @param bonusBo
  88. * @param pageNo
  89. * @param pageSize
  90. * @return
  91. */
  92. @RequestMapping(value="/technicianBonusStatistics", method = RequestMethod.GET)
  93. public Result technicianBonusStatistics(TOrderBonusBo bonusBo,Integer pageNo, Integer pageSize){
  94. Result res = new Result();
  95. bonusBo.setGrantBy(TokenManager.getAdminId());
  96. res.setData(orderBonusServiceImpl.technicianBonusStatistics(bonusBo, pageNo, pageSize));
  97. return res;
  98. }
  99. /**
  100. * 财务专员发放技术员的奖金操作
  101. * @param id
  102. * @return
  103. */
  104. @RequestMapping(value="/changeBonus", method = RequestMethod.POST)
  105. public Result changeBonus(String id){
  106. Result res = new Result();
  107. res.setData(orderBonusServiceImpl.updateChangeBonus(id));
  108. return res;
  109. }
  110. /**
  111. *
  112. * @param bonusBo
  113. * @param response
  114. * @return
  115. * @throws IOException
  116. */
  117. @RequestMapping(value="/exportSaleBonusData", method = RequestMethod.GET)
  118. public Result exportSaleBonusData(TOrderBonusBo bonusBo,HttpServletResponse response) throws IOException{
  119. OutputStream out = response.getOutputStream();
  120. Result res = new Result();
  121. bonusBo.setGrantBy(TokenManager.getAdminId());
  122. XSSFWorkbook wb = orderBonusServiceImpl.exportSaleBonusData(bonusBo);
  123. if(null == wb){
  124. wb = new XSSFWorkbook();
  125. XSSFSheet sheet = wb.createSheet("没有营销员奖金记录");
  126. XSSFRow row = sheet.createRow(0);
  127. XSSFCell cell = row.createCell(0);
  128. cell.setCellValue("没有营销员奖金记录");
  129. }
  130. String fileName = "营销员奖金统计" + new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date()) + ".xls";
  131. response.addHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes(),"iso-8859-1"));
  132. response.setContentType("application/octet-stream;charset=utf-8");
  133. try {
  134. // 返回数据流
  135. wb.write(out);
  136. out.flush();
  137. out.close();
  138. } finally {
  139. out.flush();
  140. out.close();
  141. }
  142. return res;
  143. }
  144. /**
  145. * 导出技术员(咨询师)的奖金数据
  146. * @param bonusBo
  147. * @param response
  148. * @return
  149. * @throws IOException
  150. */
  151. @RequestMapping(value="/exportTechnicianBonusData", method = RequestMethod.GET)
  152. public Result exportTechnicianBonusData(TOrderBonusBo bonusBo,HttpServletResponse response) throws IOException{
  153. OutputStream out = response.getOutputStream();
  154. Result res = new Result();
  155. bonusBo.setGrantBy(TokenManager.getAdminId());
  156. XSSFWorkbook wb = orderBonusServiceImpl.exportTechnicianBonusData(bonusBo);
  157. if(null == wb){
  158. wb = new XSSFWorkbook();
  159. XSSFSheet sheet = wb.createSheet("没有技术员奖金记录");
  160. XSSFRow row = sheet.createRow(0);
  161. XSSFCell cell = row.createCell(0);
  162. cell.setCellValue("没有技术员奖金记录");
  163. }
  164. String fileName = "技术员奖金统计" + new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date()) + ".xls";
  165. response.addHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes(),"iso-8859-1"));
  166. response.setContentType("application/octet-stream;charset=utf-8");
  167. try {
  168. // 返回数据流
  169. wb.write(out);
  170. out.flush();
  171. out.close();
  172. } finally {
  173. out.flush();
  174. out.close();
  175. }
  176. return res;
  177. }
  178. /**
  179. * 订单报表统计数据
  180. * @param reportBo
  181. * @param pageNo
  182. * @param pageSize
  183. * @return
  184. * @throws IOException
  185. */
  186. @RequestMapping(value="/orderReportList", method = RequestMethod.GET)
  187. public Result orderReportList(OrderReportBo reportBo, Integer pageNo, Integer pageSize) throws IOException{
  188. Result res = new Result();
  189. if(null == reportBo.getMonth() || null == reportBo.getMonth1()){
  190. res.getError().add(buildError("", "没有指定订单日期"));
  191. return res;
  192. }
  193. res.setData(orderReportServiceImpl.getOrderReportData(reportBo, pageNo, pageSize));
  194. return res;
  195. }
  196. /**
  197. * 导出订单数据
  198. * @param orderReportBo
  199. * @param response
  200. * @return
  201. * @throws IOException
  202. */
  203. @RequestMapping(value="/exportOrderData", method = RequestMethod.GET)
  204. public Result exportOrderData(OrderReportBo orderReportBo,HttpServletResponse response) throws IOException{
  205. //判断当前登录的角色
  206. Result res = new Result();
  207. if(null == orderReportBo.getMonth() || null == orderReportBo.getMonth1()){
  208. res.getError().add(buildError("", "没有指定订单日期"));
  209. return res;
  210. }
  211. String date = orderReportBo.getMonth() == orderReportBo.getMonth1() ? orderReportBo.getMonth().toString() : orderReportBo.getMonth() + "-" + orderReportBo.getMonth1();
  212. OutputStream out = response.getOutputStream();
  213. XSSFWorkbook wb = orderReportServiceImpl.exportMonthData(orderReportBo, date);
  214. if(null == wb){
  215. wb = new XSSFWorkbook();
  216. XSSFSheet sheet = wb.createSheet("没有订单统计记录");
  217. XSSFRow row = sheet.createRow(0);
  218. XSSFCell cell = row.createCell(0);
  219. cell.setCellValue("没有订单统计记录");
  220. }
  221. String fileName = "订单统计" + date + ".xls";
  222. response.addHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes(),"iso-8859-1"));
  223. response.setContentType("application/octet-stream;charset=utf-8");
  224. try {
  225. // 返回数据流
  226. wb.write(out);
  227. out.flush();
  228. out.close();
  229. } finally {
  230. out.flush();
  231. out.close();
  232. }
  233. return res;
  234. }
  235. /**
  236. * 导入订单模板
  237. * @param req
  238. * @return
  239. */
  240. @RequestMapping(value = "/uploadOrderExcel",method = RequestMethod.POST)
  241. public Result uploadExcel(HttpServletRequest req){
  242. Result res = new Result();
  243. String excelPath = handleFile(res, "/order_report_file/", true, req, "");
  244. ExcelUtils utils = new ExcelUtils();
  245. Set<OrderReportBo> boSet;
  246. try {
  247. boSet = utils.parseOrderExcel(uploadPrivatePath + excelPath);
  248. String errorMessage = "";
  249. //if(boSet.size()>100) errorMessage += "导入数据不能超过一百条;";
  250. errorMessage += utils.getVacantRows();
  251. if(StringUtils.isNotBlank(errorMessage)) {
  252. res.getError().add(new Error(errorMessage));
  253. return res;
  254. }
  255. Set<Integer> existRows = new TreeSet<Integer>(); //数据库已存在
  256. Set<Integer> filterRows = new TreeSet<Integer>(); //过滤提示
  257. orderReportServiceImpl.checkOrderReport(boSet,existRows,filterRows);
  258. if(existRows.size()>0){
  259. errorMessage = StringUtils.join(existRows.toArray(),",")+ " 订单统计数据已存在;";
  260. res.getError().add(new Error(errorMessage));
  261. return res;
  262. }
  263. if(filterRows.size()>0){
  264. errorMessage = StringUtils.join(filterRows.toArray(),",")+ " 行没有找到相关员工电话,已经被系统过滤;";
  265. res.getError().add(new Error(errorMessage));
  266. return res;
  267. }
  268. res.setData(orderReportServiceImpl.saveUploadData(boSet));
  269. } catch (IOException e) {
  270. e.printStackTrace();
  271. }
  272. return res;
  273. }
  274. /**
  275. * 下载年度订单数据模板
  276. * @param response
  277. * @return
  278. * @throws IOException
  279. */
  280. @RequestMapping(value = "/downOrderModelExcel",method = RequestMethod.GET)
  281. public Result downOrderModelExcel(HttpServletResponse response) throws IOException{
  282. Result res = new Result();
  283. OutputStream out = response.getOutputStream();
  284. XSSFWorkbook wb = ExportExcelUtil.downOrderModelExcel();
  285. String fileName = "导入年度销售数据模板.xls";
  286. response.addHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes(),"iso-8859-1"));
  287. response.setContentType("application/octet-stream;charset=utf-8");
  288. try {
  289. // 返回数据流
  290. wb.write(out);
  291. out.flush();
  292. out.close();
  293. } finally {
  294. out.flush();
  295. out.close();
  296. }
  297. return res;
  298. }
  299. /**
  300. * 发放营销员奖金
  301. * @param bonusBo
  302. * @return
  303. */
  304. @RequestMapping(value = "/saleBonusPayment",method = RequestMethod.POST)
  305. public Result saleBonusPayment(TOrderBonusBo bonusBo){
  306. Result res = new Result();
  307. return res;
  308. }
  309. }