ProjectStatisticsServiceImpl.java 17 KB

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