ProjectStatisticsServiceImpl.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. package com.goafanti.order.service.impl;
  2. import java.io.File;
  3. import java.io.FileOutputStream;
  4. import java.io.IOException;
  5. import java.io.OutputStream;
  6. import java.text.SimpleDateFormat;
  7. import java.util.*;
  8. import javax.servlet.http.HttpServletResponse;
  9. import javax.servlet.http.HttpServletResponseWrapper;
  10. import com.alibaba.fastjson.JSON;
  11. import com.alibaba.fastjson.JSONArray;
  12. import com.alibaba.fastjson.JSONObject;
  13. import com.goafanti.admin.service.DepartmentService;
  14. import com.goafanti.common.bo.Result;
  15. import com.goafanti.common.utils.excel.NewExcelUtil;
  16. import com.goafanti.order.bo.*;
  17. import com.goafanti.order.bo.outStatistics.*;
  18. import com.google.gson.JsonArray;
  19. import com.google.gson.JsonObject;
  20. import groovy.util.logging.Log4j;
  21. import org.apache.commons.collections4.map.HashedMap;
  22. import org.apache.commons.lang3.StringUtils;
  23. import org.apache.poi.ss.util.CellRangeAddress;
  24. import org.apache.poi.xssf.usermodel.XSSFCell;
  25. import org.apache.poi.xssf.usermodel.XSSFRow;
  26. import org.apache.poi.xssf.usermodel.XSSFSheet;
  27. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  28. import org.springframework.beans.BeanUtils;
  29. import org.springframework.beans.factory.annotation.Autowired;
  30. import org.springframework.beans.factory.annotation.Value;
  31. import org.springframework.stereotype.Service;
  32. import com.goafanti.common.bo.Error;
  33. import com.goafanti.common.dao.TOrderTaskMapper;
  34. import com.goafanti.common.error.BusinessException;
  35. import com.goafanti.common.utils.ExportExcelUtil;
  36. import com.goafanti.core.mybatis.BaseMybatisDao;
  37. import com.goafanti.core.mybatis.page.Pagination;
  38. import com.goafanti.order.enums.NewProjectStatus;
  39. import com.goafanti.order.service.ProjectStatisticsService;
  40. @Service
  41. @Log4j
  42. public class ProjectStatisticsServiceImpl extends BaseMybatisDao<TOrderTaskMapper> implements ProjectStatisticsService {
  43. @Value("${upload.path}")
  44. private String downloadPath;
  45. @Autowired
  46. private DepartmentService departmentService;
  47. @SuppressWarnings("unchecked")
  48. @Override
  49. public Pagination<OutProjectStatistics> selectTaskList(InputProjectStatistics ps) {
  50. Map<String, Object> params= new HashedMap<>();
  51. Integer pageNo=1,pageSize=10;
  52. if(ps.getStartDate()!=null)params.put("startDate", ps.getStartDate());
  53. if(ps.getEndDate()!=null)params.put("endDate", ps.getEndDate()+" 23:59:59");
  54. if(ps.getDeps()!=null)params.put("deps", departmentService.parseArray(ps.getDeps()));
  55. if(ps.getThchDeps()!=null)params.put("thchDeps", departmentService.parseArray(ps.getThchDeps()));
  56. if(ps.getProjectStatus()!=null)params.put("projectStatus", ps.getProjectStatus());
  57. if(ps.getTaskProjectStatus()!=null)params.put("taskProjectStatus", ps.getTaskProjectStatus());
  58. if(ps.getProjectType()!=null)params.put("projectType", ps.getProjectType());
  59. if(ps.getOrderNo()!=null)params.put("orderNo", ps.getOrderNo());
  60. if(ps.getContractNo()!=null)params.put("contractNo", ps.getContractNo());
  61. if(ps.getUserName()!=null)params.put("userName", ps.getUserName());
  62. if (ps.getThchId()!=null)params.put("thchId", ps.getThchId());
  63. if(ps.getDeclarationBatch()!=null)params.put("declarationBatch", ps.getDeclarationBatch());
  64. if(ps.getProjectSituation()!=null)params.put("projectSituation", ps.getProjectSituation());
  65. if(ps.getProjectAmount()!=null) {
  66. // 0~0.5万、0.5~1万、1~2万、2~5万、5~10万、10~30万、30~50万、50到80万、80万上
  67. double s = 0,e=0;
  68. if (ps.getProjectAmount()==0) { s=0;e=0.5;
  69. }else if (ps.getProjectAmount()==1) {s=0;e=0.5;
  70. }else if (ps.getProjectAmount()==2) {s=0.5;e=1;
  71. }else if (ps.getProjectAmount()==3) {s=1;e=2;
  72. }else if (ps.getProjectAmount()==4) {s=2;e=5;
  73. }else if (ps.getProjectAmount()==5) {s=5;e=10;
  74. }else if (ps.getProjectAmount()==6) {s=10;e=30;
  75. }else if (ps.getProjectAmount()==7) {s=30;e=50;
  76. }else if (ps.getProjectAmount()==8) {s=50;e=80;
  77. }else if (ps.getProjectAmount()==9) {s=80;
  78. }
  79. params.put("projectAmount", ps.getProjectAmount());
  80. params.put("amountStart", s);
  81. params.put("amountEnd", e);
  82. }
  83. params.put("status",ps.getStatus()==null?0:ps.getStatus());
  84. if(ps.getProvince()!=null) params.put("province", ps.getProvince());
  85. if(ps.getProjectId()!=null) params.put("projectId", ps.getProjectId());
  86. if(ps.getScreen()!=null) params.put("screen", ps.getScreen());
  87. if (ps.getSdStatus()!=null)params.put("sdStatus",ps.getSdStatus());
  88. if(ps.getPageNo()!=null)pageNo=ps.getPageNo();
  89. if(ps.getPageSize()!=null)pageSize=ps.getPageSize();
  90. Pagination<OutProjectStatistics> p = (Pagination<OutProjectStatistics>)findPage("selectProjectStatisticsListByPage",
  91. "selectProjectStatisticsCount", params, pageNo, pageSize);
  92. return p;
  93. }
  94. @Override
  95. public Result exporTaskList( InputProjectStatistics ib,HttpServletResponse response) {
  96. if(ib.getPageSize()==null)ib.setPageSize(9999999);
  97. if(ib.getStatus()==null)ib.setStatus(0);
  98. @SuppressWarnings("unchecked")
  99. List<OutProjectStatistics> list= (List<OutProjectStatistics>) selectTaskList(ib).getList();
  100. Result res =new Result();
  101. if (ib.getStatus()==null||ib.getStatus()==0){
  102. List<OutProjectStatisticsCommon> tl=new ArrayList<>();
  103. for (OutProjectStatistics o : list) {
  104. OutProjectStatisticsCommon common = new OutProjectStatisticsCommon();
  105. BeanUtils.copyProperties(o,common);
  106. tl.add(common);
  107. }
  108. NewExcelUtil<OutProjectStatisticsCommon> excelUtil=new NewExcelUtil<>(OutProjectStatisticsCommon.class);
  109. res=excelUtil.exportExcel(tl,"项目汇总表(通用)",downloadPath);
  110. }else if (ib.getStatus()==1){//高新、科技
  111. List<OutProjectStatisticsHighTech> tl=new ArrayList<>();
  112. for (OutProjectStatistics o : list) {
  113. OutProjectStatisticsHighTech highTech = new OutProjectStatisticsHighTech();
  114. BeanUtils.copyProperties(o,highTech);
  115. tl.add(highTech);
  116. }
  117. NewExcelUtil<OutProjectStatisticsHighTech> excelUtil=new NewExcelUtil<>(OutProjectStatisticsHighTech.class);
  118. res=excelUtil.exportExcel(tl,"项目汇总表(高新)",downloadPath);
  119. }else if (ib.getStatus()==2){//双软
  120. List<OutProjectStatisticsDoubleSoft> tl=new ArrayList<>();
  121. for (OutProjectStatistics o : list) {
  122. OutProjectStatisticsDoubleSoft doubleSoft = new OutProjectStatisticsDoubleSoft();
  123. BeanUtils.copyProperties(o,doubleSoft);
  124. tl.add(doubleSoft);
  125. }
  126. NewExcelUtil<OutProjectStatisticsDoubleSoft> excelUtil=new NewExcelUtil<>(OutProjectStatisticsDoubleSoft.class);
  127. res=excelUtil.exportExcel(tl,"项目汇总表(双软)",downloadPath);
  128. }else if (ib.getStatus()==3){//软著
  129. List<OutProjectStatisticsSoftwareWorks> tl=new ArrayList<>();
  130. for (OutProjectStatistics o : list) {
  131. OutProjectStatisticsSoftwareWorks softwareWorks = new OutProjectStatisticsSoftwareWorks();
  132. BeanUtils.copyProperties(o,softwareWorks);
  133. softwareWorks.setQuantityAndcount(softwareWorks.getCommodityQuantity()+"/"+softwareWorks.getCertificatesCount());
  134. tl.add(softwareWorks);
  135. }
  136. NewExcelUtil<OutProjectStatisticsSoftwareWorks> excelUtil=new NewExcelUtil<>(OutProjectStatisticsSoftwareWorks.class);
  137. res=excelUtil.exportExcel(tl,"项目汇总表(软著)",downloadPath);
  138. }else if (ib.getStatus()==4){//软著
  139. List<OutProjectStatisticsPatent> tl=new ArrayList<>();
  140. for (OutProjectStatistics o : list) {
  141. OutProjectStatisticsPatent patent = new OutProjectStatisticsPatent();
  142. BeanUtils.copyProperties(o,patent);
  143. patent.setQuantityAndcount(patent.getCommodityQuantity()+"/"+patent.getCertificatesCount());
  144. tl.add(patent);
  145. }
  146. NewExcelUtil<OutProjectStatisticsPatent> excelUtil=new NewExcelUtil<>(OutProjectStatisticsPatent.class);
  147. res=excelUtil.exportExcel(tl,"项目汇总表(专利)",downloadPath);
  148. }else if (ib.getStatus()==5){//会员
  149. List<OutProjectStatisticsMember> tl=new ArrayList<>();
  150. for (OutProjectStatistics o : list) {
  151. OutProjectStatisticsMember member = new OutProjectStatisticsMember();
  152. BeanUtils.copyProperties(o,member);
  153. if (member.getServiceLife()!=null){
  154. JSONArray jsonArray = JSONArray.parseArray(member.getServiceLife());
  155. Object[] object=jsonArray.stream().toArray();
  156. member.setServiceLife(StringUtils.join(object,","));
  157. }
  158. if (member.getContractTerm()!=null){
  159. JSONArray jsonArray = JSONArray.parseArray(member.getContractTerm());
  160. Object[] object=jsonArray.stream().toArray();
  161. member.setContractTerm(StringUtils.join(object,"~"));
  162. }
  163. tl.add(member);
  164. }
  165. NewExcelUtil<OutProjectStatisticsMember> excelUtil=new NewExcelUtil<>(OutProjectStatisticsMember.class);
  166. res=excelUtil.exportExcel(tl,"项目汇总表(会员)",downloadPath);
  167. }else if (ib.getStatus()==6){//会员
  168. List<OutProjectStatisticsAudit> tl=new ArrayList<>();
  169. for (OutProjectStatistics o : list) {
  170. OutProjectStatisticsAudit audit = new OutProjectStatisticsAudit();
  171. BeanUtils.copyProperties(o,audit);
  172. if (audit.getServiceLife()!=null){
  173. JSONArray jsonArray = JSONArray.parseArray(audit.getServiceLife());
  174. Object[] object=jsonArray.stream().toArray();
  175. audit.setServiceLife(StringUtils.join(object,","));
  176. }
  177. if (audit.getContractTerm()!=null){
  178. JSONArray jsonArray = JSONArray.parseArray(audit.getContractTerm());
  179. Object[] object=jsonArray.stream().toArray();
  180. audit.setContractTerm(StringUtils.join(object,"~"));
  181. }
  182. tl.add(audit);
  183. }
  184. NewExcelUtil<OutProjectStatisticsAudit> excelUtil=new NewExcelUtil<>(OutProjectStatisticsAudit.class);
  185. res=excelUtil.exportExcel(tl,"项目汇总表(审计)",downloadPath);
  186. }
  187. return res;
  188. }
  189. @SuppressWarnings("unchecked")
  190. @Override
  191. public Pagination<OutProvincialStatistics> selectProvincialStatistics(InputProvincialStatistics is) {
  192. Map<String, Object> params= new HashedMap<>();
  193. Integer pageNo=1,pageSize=10;
  194. if(is.getStartDate()!=null)params.put("startDate", is.getStartDate());
  195. if(is.getEndDate()!=null)params.put("endDate", is.getEndDate()+" 23:59:59");
  196. if(is.getThchDeps()!=null)params.put("thchDeps", departmentService.parseArray(is.getThchDeps()));
  197. if(is.getProjectStatus()!=null)params.put("projectStatus", is.getProjectStatus());
  198. if(is.getProjectType()!=null)params.put("projectType", is.getProjectType());
  199. if(is.getProvince()!=null)params.put("province", is.getProvince());
  200. if(is.getProjectId()!=null)params.put("projectId", is.getProjectId());
  201. params.put("status",is.getStatus()==null?0:is.getStatus());
  202. if(is.getPageNo()!=null)pageNo=is.getPageNo();
  203. if(is.getPageSize()!=null)pageSize=is.getPageSize();
  204. Pagination<OutProvincialStatistics> p = (Pagination<OutProvincialStatistics>)findPage("selectProvincialStatisticsListByPage",
  205. "selectProvincialStatisticsCount", params, pageNo, pageSize);
  206. return p;
  207. }
  208. @Override
  209. public Result exporProvincialList(InputProvincialStatistics ib) {
  210. OutputStream out = null;
  211. XSSFWorkbook wb=null;
  212. try {
  213. if(ib.getPageSize()==null)ib.setPageSize(9999999);
  214. if(ib.getStatus()==null)ib.setStatus(0);
  215. @SuppressWarnings("unchecked")
  216. List<OutProvincialStatistics> list= (List<OutProvincialStatistics>) selectProvincialStatistics(ib).getList();
  217. //派单賞份负责部门项目类別陸存数(个)派单数(个)下证数(个)签单额(万元)成本(万元)利润(万元)
  218. String[] comment = {"派单省份","负责部门","项目别类","库存数","派单数"};
  219. List<String> ls = new ArrayList<String>();
  220. Collections.addAll(ls, comment);
  221. if (ib.getStatus()==1) {
  222. //高新
  223. //是否立项 立项时间 是否抽查 联系人电话 法人电话 证书编号 申报批次
  224. String[] ss= {"完成数","立项数","抽查数","未通过"};
  225. Collections.addAll(ls, ss);
  226. }else if (ib.getStatus()==2||ib.getStatus()==3) {
  227. //发明专利、实用新型
  228. ls.add("受理数");
  229. ls.add("完结数");
  230. ls.add("授权数");
  231. ls.add("驳回数");
  232. }else if (ib.getStatus()==4) {
  233. //软著
  234. ls.add("下证数");
  235. }else if (ib.getStatus()==5) {
  236. //商标
  237. String[] ss= {"申请数","驳回数","下证数"};
  238. Collections.addAll(ls, ss);
  239. }else if (ib.getStatus()==0) {
  240. String[] ss= {"完成数","公示数"};
  241. Collections.addAll(ls, ss);
  242. }
  243. String[] ss= {"签单额(万元)","成本(万元)","利润(万元)"};
  244. Collections.addAll(ls, ss);
  245. comment= ls.toArray(new String[ls.size()]);
  246. // String fileName ="项目数据统计" + new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date()) + ".xls";
  247. String filename = UUID.randomUUID().toString() + "_ProvincialList.xlsx";
  248. wb =ExportExcelUtil.exportTemplateInfoS(comment,"项目数据统计");
  249. //根据列表编写文档
  250. XSSFSheet sheet =wb.getSheetAt(0);
  251. XSSFRow xr = sheet.createRow(sheet.getLastRowNum()+1);
  252. //4.创建一个cell
  253. XSSFCell cell = xr.createCell(0);
  254. cell.setCellValue(getProvincialInputString(ib));
  255. sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, comment.length-1));//合并单元格
  256. for (OutProvincialStatistics ob : list) {
  257. //新增一行
  258. XSSFRow r = sheet.createRow(sheet.getLastRowNum()+1);
  259. for (int i = 0; i < comment.length; i++) {
  260. //当前列的只
  261. String o = "";
  262. switch (comment[i]) {
  263. // "派单省份","负责部门","项目别类","库存数(个)","派单数(个)","下证数(个)","签单数(个)","成本(万元)","利润(万元)"
  264. case "派单省份": o = ob.getProvinceName(); break;
  265. case "负责部门": o = ob.getThchDepName(); break;
  266. case "项目别类": o = ob.getProjectStatus(); break;
  267. case "库存数": o = ob.getStockCount().toString(); break;
  268. case "派单数": o = ob.getDistributeCount().toString(); break;
  269. //"完成数","立项数","抽查数","未通过"
  270. case "完成数": o = ob.getCompleteCount().toString(); break;
  271. case "立项数": o = ob.getSetUpCount().toString(); break;
  272. case "抽查数": o = ob.getSpotCheckCount().toString(); break;
  273. case "未通过": o = ob.getFailedCount().toString(); break;
  274. //受理数 完结数 授权数 驳回数
  275. case "受理数": o = ob.getAcceptCount().toString(); break;
  276. case "完结数": o = ob.getCompleteCount().toString(); break;
  277. case "授权数": o = ob.getAuthorizeCount().toString(); break;
  278. case "驳回数": o = ob.getRejectCount().toString(); break;
  279. //下证数
  280. case "下证数": o = ob.getCertificatesCount().toString(); break;
  281. //"申请数","驳回数","下证数"
  282. case "申请数": o = ob.getApplyCount().toString(); break;
  283. //"完成数","公示/立项数"
  284. case "公示数": o = ob.getPublicityCount().toString(); break;
  285. case "签单额(万元)": o = ob.getAmountCount().stripTrailingZeros().toPlainString(); break;
  286. case "成本(万元)": o = ob.getCostAmount().stripTrailingZeros().toPlainString(); break;
  287. case "利润(万元)": o = ob.getProfit().stripTrailingZeros().toPlainString(); break;
  288. default: o = ""; break;
  289. }
  290. XSSFCell c = r.createCell(i);
  291. c.setCellValue(o);
  292. }
  293. }
  294. String downloadPath = this.downloadPath+"/" + filename;
  295. File desc = new File(downloadPath);
  296. if (!desc.getParentFile().exists()) {
  297. desc.getParentFile().mkdirs();
  298. }
  299. out=new FileOutputStream(downloadPath);
  300. // 返回数据流
  301. wb.write(out);
  302. return new Result().data(filename);
  303. } catch (Exception e) {
  304. e.printStackTrace();
  305. throw new BusinessException(new Error("表格生成错误。"));
  306. }finally {
  307. if (out != null) {
  308. try {
  309. out.close();
  310. } catch (IOException e1) {
  311. e1.printStackTrace();
  312. }
  313. }
  314. if (wb !=null){
  315. try {
  316. wb.close();
  317. } catch (IOException e1) {
  318. e1.printStackTrace();
  319. }
  320. }
  321. }
  322. }
  323. private String getProvincialInputString(InputProvincialStatistics ib) {
  324. String str="搜索条件:";
  325. int i=1;
  326. if(ib.getStartDate()!=null) str=StringUtils.join(str,i++,"-开始时间:",ib.getStartDate()," ");
  327. if(ib.getEndDate()!=null)str=StringUtils.join(str,i++,"-结束时间:",ib.getEndDate()," ");
  328. if(ib.getProvince()!=null)str=StringUtils.join(str,i++,"-省份:",ib.getProvinceName()," ");
  329. if(ib.getThchDeps()!=null)str=StringUtils.join(str,i++,"-责任部门:",ib.getThchDepName()," ");
  330. if(ib.getProjectStatus()!=null)str=StringUtils.join(str,i++,"-项目别类:",ib.getProjectStatusName()," ");
  331. if(ib.getProjectType()!=null)str=StringUtils.join(str,i++,"-项目分类:",ib.getProjectTypeName()," ");
  332. if(ib.getProjectId()!=null)str=StringUtils.join(str,i++,"-项目名称:",ib.getProjectName()," ");
  333. if(i==1)StringUtils.join(str,"无");
  334. return str;
  335. }
  336. }