77eeeff2df1e53a360ca0c4818d06ea7973601f2.svn-base 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. package cn.com.goldenwater.dcproj.service.impl.plan;
  2. import cn.com.goldenwater.dcproj.dao.BisInspMtprggdDao;
  3. import cn.com.goldenwater.dcproj.model.BisInspMtprggd;
  4. import cn.com.goldenwater.dcproj.param.BisInspMtprggdParam;
  5. import cn.com.goldenwater.dcproj.param.BisInspPlanYearPrgParam;
  6. import cn.com.goldenwater.dcproj.service.BisInspMtprggdService;
  7. import cn.com.goldenwater.core.service.AbstractCrudService;
  8. import cn.com.goldenwater.dcproj.utils.StringUtils;
  9. import org.apache.poi.ss.usermodel.*;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.beans.factory.annotation.Value;
  12. import org.springframework.stereotype.Service;
  13. import org.springframework.transaction.annotation.Transactional;
  14. import cn.com.goldenwater.id.util.UuidUtil;
  15. import javax.servlet.http.HttpServletResponse;
  16. import java.io.*;
  17. import java.net.URLEncoder;
  18. import java.text.SimpleDateFormat;
  19. import java.util.ArrayList;
  20. import java.util.List;
  21. import java.util.Date;
  22. import java.util.Map;
  23. /**
  24. * @author lhc
  25. * @date 2022-3-17
  26. */
  27. @Service
  28. @Transactional
  29. public class BisInspMtprggdServiceImpl extends AbstractCrudService<BisInspMtprggd, BisInspMtprggdParam> implements BisInspMtprggdService {
  30. @Autowired
  31. private BisInspMtprggdDao bisInspMtprggdDao;
  32. @Value("${export.templatePath}")
  33. private String templatePath;
  34. private final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  35. private final SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM");
  36. public BisInspMtprggdServiceImpl(BisInspMtprggdDao bisInspMtprggdDao) {
  37. super(bisInspMtprggdDao);
  38. this.bisInspMtprggdDao = bisInspMtprggdDao;
  39. }
  40. @Override
  41. public int insert(BisInspMtprggd bisInspMtprggd) {
  42. String uuid = UuidUtil.uuid(); // 生成uuid
  43. bisInspMtprggd.setId(uuid);
  44. bisInspMtprggd.setIntm(new Date());
  45. bisInspMtprggd.setUptm(new Date());
  46. bisInspMtprggd.setDataStat("0");
  47. return this.bisInspMtprggdDao.insert(bisInspMtprggd);
  48. }
  49. @Override
  50. public int update(BisInspMtprggd bisInspMtprggd) {
  51. bisInspMtprggd.setUptm(new Date());
  52. return this.bisInspMtprggdDao.update(bisInspMtprggd);
  53. }
  54. @Override
  55. public int delete(String id) {
  56. return this.bisInspMtprggdDao.delete(id);
  57. }
  58. @Override
  59. public List<Map<String, String>> getMonthRefrom(Map<String, String> parmas) {
  60. List<Map<String,String>> listAll = new ArrayList<Map<String,String>>();
  61. List<Map<String,String>> list = this.bisInspMtprggdDao.getMonthRefrom(parmas);
  62. if(list!=null && list.size()>0){
  63. for(int i = 0;i<list.size();i++){
  64. List<Map<String,String>> list1 = this.bisInspMtprggdDao.getObjNames(list.get(i).get("ID"));
  65. if(list1!=null && list1.size()>0){
  66. String nameStr = "";
  67. for(int j = 0;j<list1.size();j++){
  68. if(j==list1.size()-1){
  69. nameStr+=list1.get(j).get("NM");
  70. }else{
  71. nameStr+=list1.get(j).get("NM")+"," ;
  72. }
  73. }
  74. list.get(i).put("OBJNAMES",nameStr);
  75. if(StringUtils.isNotBlank(parmas.get("objName"))){
  76. if(list.get(i).get("OBJNAMES").indexOf(parmas.get("objName"))>-1){
  77. listAll.add(list.get(i));
  78. }
  79. }
  80. }
  81. }
  82. }
  83. if(StringUtils.isNotBlank(parmas.get("objName"))){
  84. return listAll;
  85. }else{
  86. return list;
  87. }
  88. }
  89. @Override
  90. public void export(HttpServletResponse response, Map<String, String> parmas) {
  91. String templateFilePath = templatePath+ File.separator +"yjhtc.xls";
  92. File file = new File(templateFilePath);
  93. if(file.exists()){
  94. try{
  95. InputStream inputStream = new FileInputStream(file);
  96. Workbook workbook = WorkbookFactory.create(inputStream);
  97. exportFile(workbook,parmas);
  98. writeToResponse(response,workbook,"月统筹计划.xls");
  99. }catch(Exception e){
  100. e.printStackTrace();
  101. }
  102. }
  103. }
  104. @Override
  105. public List<BisInspMtprggd> findListByMonth(BisInspPlanYearPrgParam bisInspPlanYearPrgParam) {
  106. return bisInspMtprggdDao.findListByMonth(bisInspPlanYearPrgParam);
  107. }
  108. @Override
  109. public void exportMonth(HttpServletResponse response, BisInspMtprggdParam bisInspMtprggdParam,BisInspPlanYearPrgParam bisInspPlanYearPrgParam,String type) {
  110. String templateFilePath = templatePath+ File.separator +"monthGd.xls";
  111. File file = new File(templateFilePath);
  112. if(file.exists()){
  113. try{
  114. InputStream inputStream = new FileInputStream(file);
  115. Workbook workbook = WorkbookFactory.create(inputStream);
  116. exportFileMonth(workbook,bisInspMtprggdParam,bisInspPlanYearPrgParam,type);
  117. writeToResponse(response,workbook,"月进展情况.xls");
  118. }catch(Exception e){
  119. e.printStackTrace();
  120. }
  121. }
  122. }
  123. private void exportFileMonth(Workbook xssfWorkbook, BisInspMtprggdParam bisInspMtprggdParam,BisInspPlanYearPrgParam bisInspPlanYearPrgParam,String type) {
  124. String title = "月进展情况";
  125. List<BisInspMtprggd> list = null;
  126. if(StringUtils.isNotBlank(type)){
  127. list = bisInspMtprggdDao.findListByMonth(bisInspPlanYearPrgParam);
  128. }else{
  129. list = bisInspMtprggdDao.findList(bisInspMtprggdParam);
  130. }
  131. Sheet sheet = xssfWorkbook.getSheetAt(0);
  132. if(list!=null && list.size()>0){
  133. for(int i = 0;i<list.size();i++){
  134. Row row = sheet.createRow(4+i);
  135. int cols = 20;
  136. for(int j = 0;j<=cols;j++){
  137. Cell cell = row.createCell(j);
  138. }
  139. }
  140. for(int i = 0;i<list.size();i++){
  141. BisInspMtprggd bisInspMtprggd = list.get(i);
  142. setAllCell(sheet,i,bisInspMtprggd);
  143. }
  144. }
  145. }
  146. private void setAllCell(Sheet sheet, int i, BisInspMtprggd bisInspMtprggd) {
  147. setCellValue(sheet, 4 + i, 0, String.valueOf(i + 1));
  148. setCellValue(sheet, 4 + i, 1, bisInspMtprggd.getUnitName());
  149. setCellValue(sheet, 4 + i, 2, bisInspMtprggd.getYear().toString());
  150. setCellValue(sheet, 4 + i, 3, bisInspMtprggd.getMnth().toString());
  151. setCellValue(sheet, 4 + i, 4, "0".equals(bisInspMtprggd.getPtype())?"暗访":("1".equals(bisInspMtprggd.getPtype()))?"明查":("2".equals(bisInspMtprggd.getPtype()))?"线上":("3".equals(bisInspMtprggd.getPtype()))?"明查+暗访":"");
  152. setCellValue(sheet, 4 + i, 5, simpleDateFormat1.format(bisInspMtprggd.getTm())+"~"+simpleDateFormat1.format(bisInspMtprggd.getEm()));
  153. setCellValue(sheet, 4 + i, 6, bisInspMtprggd.getPrjSize().toString());
  154. setCellValue(sheet, 4 + i, 7, bisInspMtprggd.getDepSize().toString());
  155. setCellValue(sheet, 4 + i, 8, bisInspMtprggd.getChkSize().toString());
  156. setCellValue(sheet, 4 + i, 9, bisInspMtprggd.getLeadSize().toString());
  157. setCellValue(sheet, 4 + i, 10,bisInspMtprggd.getChkDaySize().toString());
  158. setCellValue(sheet, 4 + i, 11,bisInspMtprggd.getFeedBackSize().toString());
  159. setCellValue(sheet, 4 + i, 12,bisInspMtprggd.getPblmSize().toString());
  160. setCellValue(sheet, 4 + i, 13,bisInspMtprggd.getMendSize().toString());
  161. setCellValue(sheet, 4 + i, 14,bisInspMtprggd.getMendCmpSize().toString());
  162. setCellValue(sheet, 4 + i, 15,bisInspMtprggd.getMendCmpTatSize().toString());
  163. setCellValue(sheet, 4 + i, 16,bisInspMtprggd.getMendCmpRatio().toString());
  164. setCellValue(sheet, 4 + i, 17,bisInspMtprggd.getAccuntDep());
  165. setCellValue(sheet, 4 + i, 18,bisInspMtprggd.getAccuntText());
  166. setCellValue(sheet, 4 + i, 19,simpleDateFormat.format(bisInspMtprggd.getAcuntTm()));
  167. setCellValue(sheet, 4 + i, 20,bisInspMtprggd.getAccuntNote());
  168. }
  169. private void exportFile(Workbook xssfWorkbook, Map<String, String> parmas) {
  170. List<Map<String,String>> list = getMonthRefrom(parmas);
  171. Sheet sheet = xssfWorkbook.getSheetAt(0);
  172. String title = "月统筹计划";
  173. if(StringUtils.isNotBlank(parmas.get("sttm")) && StringUtils.isNotBlank(parmas.get("entm"))){
  174. title = parmas.get("sttm")+"~"+parmas.get("entm")+title;
  175. }
  176. CellStyle styleContent = xssfWorkbook.createCellStyle();
  177. styleContent.setAlignment(HorizontalAlignment.CENTER);
  178. styleContent.setVerticalAlignment(VerticalAlignment.CENTER);
  179. setCellValue(sheet, 0, 1, title);
  180. if(list!=null && list.size()>0){
  181. for(int i = 0;i<list.size();i++){
  182. Row row = sheet.createRow(2+i);
  183. int cols = 11;
  184. for(int j = 0;j<=cols;j++){
  185. Cell cell = row.createCell(j);
  186. cell.setCellStyle(styleContent);
  187. }
  188. }
  189. for(int i = 0;i<list.size();i++){
  190. Map<String,String> map = list.get(i);
  191. setAllCell(sheet,i,map);
  192. }
  193. }
  194. }
  195. private void setAllCell(Sheet sheet, int i, Map<String,String> map) {
  196. setCellValue(sheet, 2 + i, 0, String.valueOf(i + 1));
  197. setCellValue(sheet, 2 + i, 1, map.get("GROUPNAME"));
  198. setCellValue(sheet, 2 + i, 2, map.get("OBJNAME"));
  199. setCellValue(sheet, 2 + i, 3, (map.get("STTM")==null?"":map.get("STTM"))+(map.get("ENTM")==null?"":"~"+map.get("ENTM")));
  200. setCellValue(sheet, 2 + i, 4, map.get("CHKAREA"));
  201. setCellValue(sheet, 2 + i, 5, String.valueOf(map.get("COUNT")));
  202. setCellValue(sheet, 2 + i, 6, "1".equals(map.get("CHKFORM"))?"暗访":"2".equals(map.get("CHKFORM"))?"明察":"3".equals(map.get("CHKFORM"))?"书面":"4".equals(map.get("CHKFORM"))?"四不两直":"");
  203. setCellValue(sheet, 2 + i, 7, map.get("LEADDEP"));
  204. setCellValue(sheet, 2 + i, 8, map.get("PERSNAME"));
  205. setCellValue(sheet, 2 + i, 9, map.get("MOBILENUMB"));
  206. setCellValue(sheet, 2 + i, 10,map.get("OBJNAMES"));
  207. }
  208. private void setCellValue(Sheet sheet, int rownum, int cellnum, String value) {
  209. Cell cell = sheet.getRow(rownum).getCell(cellnum);
  210. cell.setCellValue(value);
  211. }
  212. private void writeToResponse(HttpServletResponse response, Workbook workbook, String name) throws IOException {
  213. // 修改模板内容导出新模板
  214. response.setContentType("application/x-msdownload");
  215. String fileNameURL = URLEncoder.encode(name, "UTF-8");
  216. response.setHeader("Content-disposition", "attachment;filename=" + fileNameURL + ";filename*=utf-8''" + fileNameURL);
  217. OutputStream out = response.getOutputStream();
  218. workbook.write(out);
  219. out.flush();
  220. out.close();
  221. }
  222. }