| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- package cn.com.goldenwater.dcproj.service.impl.plan;
- import cn.com.goldenwater.dcproj.dao.BisInspMtprggdDao;
- import cn.com.goldenwater.dcproj.model.BisInspMtprggd;
- import cn.com.goldenwater.dcproj.param.BisInspMtprggdParam;
- import cn.com.goldenwater.dcproj.param.BisInspPlanYearPrgParam;
- import cn.com.goldenwater.dcproj.service.BisInspMtprggdService;
- import cn.com.goldenwater.core.service.AbstractCrudService;
- import cn.com.goldenwater.dcproj.utils.StringUtils;
- import org.apache.poi.ss.usermodel.*;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import cn.com.goldenwater.id.util.UuidUtil;
- import javax.servlet.http.HttpServletResponse;
- import java.io.*;
- import java.net.URLEncoder;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Date;
- import java.util.Map;
- /**
- * @author lhc
- * @date 2022-3-17
- */
- @Service
- @Transactional
- public class BisInspMtprggdServiceImpl extends AbstractCrudService<BisInspMtprggd, BisInspMtprggdParam> implements BisInspMtprggdService {
- @Autowired
- private BisInspMtprggdDao bisInspMtprggdDao;
- @Value("${export.templatePath}")
- private String templatePath;
- private final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
- private final SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM");
- public BisInspMtprggdServiceImpl(BisInspMtprggdDao bisInspMtprggdDao) {
- super(bisInspMtprggdDao);
- this.bisInspMtprggdDao = bisInspMtprggdDao;
- }
- @Override
- public int insert(BisInspMtprggd bisInspMtprggd) {
- String uuid = UuidUtil.uuid(); // 生成uuid
- bisInspMtprggd.setId(uuid);
- bisInspMtprggd.setIntm(new Date());
- bisInspMtprggd.setUptm(new Date());
- bisInspMtprggd.setDataStat("0");
- return this.bisInspMtprggdDao.insert(bisInspMtprggd);
- }
- @Override
- public int update(BisInspMtprggd bisInspMtprggd) {
- bisInspMtprggd.setUptm(new Date());
- return this.bisInspMtprggdDao.update(bisInspMtprggd);
- }
- @Override
- public int delete(String id) {
- return this.bisInspMtprggdDao.delete(id);
- }
- @Override
- public List<Map<String, String>> getMonthRefrom(Map<String, String> parmas) {
- List<Map<String,String>> listAll = new ArrayList<Map<String,String>>();
- List<Map<String,String>> list = this.bisInspMtprggdDao.getMonthRefrom(parmas);
- if(list!=null && list.size()>0){
- for(int i = 0;i<list.size();i++){
- List<Map<String,String>> list1 = this.bisInspMtprggdDao.getObjNames(list.get(i).get("ID"));
- if(list1!=null && list1.size()>0){
- String nameStr = "";
- for(int j = 0;j<list1.size();j++){
- if(j==list1.size()-1){
- nameStr+=list1.get(j).get("NM");
- }else{
- nameStr+=list1.get(j).get("NM")+"," ;
- }
- }
- list.get(i).put("OBJNAMES",nameStr);
- if(StringUtils.isNotBlank(parmas.get("objName"))){
- if(list.get(i).get("OBJNAMES").indexOf(parmas.get("objName"))>-1){
- listAll.add(list.get(i));
- }
- }
- }
- }
- }
- if(StringUtils.isNotBlank(parmas.get("objName"))){
- return listAll;
- }else{
- return list;
- }
- }
- @Override
- public void export(HttpServletResponse response, Map<String, String> parmas) {
- String templateFilePath = templatePath+ File.separator +"yjhtc.xls";
- File file = new File(templateFilePath);
- if(file.exists()){
- try{
- InputStream inputStream = new FileInputStream(file);
- Workbook workbook = WorkbookFactory.create(inputStream);
- exportFile(workbook,parmas);
- writeToResponse(response,workbook,"月统筹计划.xls");
- }catch(Exception e){
- e.printStackTrace();
- }
- }
- }
- @Override
- public List<BisInspMtprggd> findListByMonth(BisInspPlanYearPrgParam bisInspPlanYearPrgParam) {
- return bisInspMtprggdDao.findListByMonth(bisInspPlanYearPrgParam);
- }
- @Override
- public void exportMonth(HttpServletResponse response, BisInspMtprggdParam bisInspMtprggdParam,BisInspPlanYearPrgParam bisInspPlanYearPrgParam,String type) {
- String templateFilePath = templatePath+ File.separator +"monthGd.xls";
- File file = new File(templateFilePath);
- if(file.exists()){
- try{
- InputStream inputStream = new FileInputStream(file);
- Workbook workbook = WorkbookFactory.create(inputStream);
- exportFileMonth(workbook,bisInspMtprggdParam,bisInspPlanYearPrgParam,type);
- writeToResponse(response,workbook,"月进展情况.xls");
- }catch(Exception e){
- e.printStackTrace();
- }
- }
- }
- private void exportFileMonth(Workbook xssfWorkbook, BisInspMtprggdParam bisInspMtprggdParam,BisInspPlanYearPrgParam bisInspPlanYearPrgParam,String type) {
- String title = "月进展情况";
- List<BisInspMtprggd> list = null;
- if(StringUtils.isNotBlank(type)){
- list = bisInspMtprggdDao.findListByMonth(bisInspPlanYearPrgParam);
- }else{
- list = bisInspMtprggdDao.findList(bisInspMtprggdParam);
- }
- Sheet sheet = xssfWorkbook.getSheetAt(0);
- if(list!=null && list.size()>0){
- for(int i = 0;i<list.size();i++){
- Row row = sheet.createRow(4+i);
- int cols = 20;
- for(int j = 0;j<=cols;j++){
- Cell cell = row.createCell(j);
- }
- }
- for(int i = 0;i<list.size();i++){
- BisInspMtprggd bisInspMtprggd = list.get(i);
- setAllCell(sheet,i,bisInspMtprggd);
- }
- }
- }
- private void setAllCell(Sheet sheet, int i, BisInspMtprggd bisInspMtprggd) {
- setCellValue(sheet, 4 + i, 0, String.valueOf(i + 1));
- setCellValue(sheet, 4 + i, 1, bisInspMtprggd.getUnitName());
- setCellValue(sheet, 4 + i, 2, bisInspMtprggd.getYear().toString());
- setCellValue(sheet, 4 + i, 3, bisInspMtprggd.getMnth().toString());
- setCellValue(sheet, 4 + i, 4, "0".equals(bisInspMtprggd.getPtype())?"暗访":("1".equals(bisInspMtprggd.getPtype()))?"明查":("2".equals(bisInspMtprggd.getPtype()))?"线上":("3".equals(bisInspMtprggd.getPtype()))?"明查+暗访":"");
- setCellValue(sheet, 4 + i, 5, simpleDateFormat1.format(bisInspMtprggd.getTm())+"~"+simpleDateFormat1.format(bisInspMtprggd.getEm()));
- setCellValue(sheet, 4 + i, 6, bisInspMtprggd.getPrjSize().toString());
- setCellValue(sheet, 4 + i, 7, bisInspMtprggd.getDepSize().toString());
- setCellValue(sheet, 4 + i, 8, bisInspMtprggd.getChkSize().toString());
- setCellValue(sheet, 4 + i, 9, bisInspMtprggd.getLeadSize().toString());
- setCellValue(sheet, 4 + i, 10,bisInspMtprggd.getChkDaySize().toString());
- setCellValue(sheet, 4 + i, 11,bisInspMtprggd.getFeedBackSize().toString());
- setCellValue(sheet, 4 + i, 12,bisInspMtprggd.getPblmSize().toString());
- setCellValue(sheet, 4 + i, 13,bisInspMtprggd.getMendSize().toString());
- setCellValue(sheet, 4 + i, 14,bisInspMtprggd.getMendCmpSize().toString());
- setCellValue(sheet, 4 + i, 15,bisInspMtprggd.getMendCmpTatSize().toString());
- setCellValue(sheet, 4 + i, 16,bisInspMtprggd.getMendCmpRatio().toString());
- setCellValue(sheet, 4 + i, 17,bisInspMtprggd.getAccuntDep());
- setCellValue(sheet, 4 + i, 18,bisInspMtprggd.getAccuntText());
- setCellValue(sheet, 4 + i, 19,simpleDateFormat.format(bisInspMtprggd.getAcuntTm()));
- setCellValue(sheet, 4 + i, 20,bisInspMtprggd.getAccuntNote());
- }
- private void exportFile(Workbook xssfWorkbook, Map<String, String> parmas) {
- List<Map<String,String>> list = getMonthRefrom(parmas);
- Sheet sheet = xssfWorkbook.getSheetAt(0);
- String title = "月统筹计划";
- if(StringUtils.isNotBlank(parmas.get("sttm")) && StringUtils.isNotBlank(parmas.get("entm"))){
- title = parmas.get("sttm")+"~"+parmas.get("entm")+title;
- }
- CellStyle styleContent = xssfWorkbook.createCellStyle();
- styleContent.setAlignment(HorizontalAlignment.CENTER);
- styleContent.setVerticalAlignment(VerticalAlignment.CENTER);
- setCellValue(sheet, 0, 1, title);
- if(list!=null && list.size()>0){
- for(int i = 0;i<list.size();i++){
- Row row = sheet.createRow(2+i);
- int cols = 11;
- for(int j = 0;j<=cols;j++){
- Cell cell = row.createCell(j);
- cell.setCellStyle(styleContent);
- }
- }
- for(int i = 0;i<list.size();i++){
- Map<String,String> map = list.get(i);
- setAllCell(sheet,i,map);
- }
- }
- }
- private void setAllCell(Sheet sheet, int i, Map<String,String> map) {
- setCellValue(sheet, 2 + i, 0, String.valueOf(i + 1));
- setCellValue(sheet, 2 + i, 1, map.get("GROUPNAME"));
- setCellValue(sheet, 2 + i, 2, map.get("OBJNAME"));
- setCellValue(sheet, 2 + i, 3, (map.get("STTM")==null?"":map.get("STTM"))+(map.get("ENTM")==null?"":"~"+map.get("ENTM")));
- setCellValue(sheet, 2 + i, 4, map.get("CHKAREA"));
- setCellValue(sheet, 2 + i, 5, String.valueOf(map.get("COUNT")));
- 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"))?"四不两直":"");
- setCellValue(sheet, 2 + i, 7, map.get("LEADDEP"));
- setCellValue(sheet, 2 + i, 8, map.get("PERSNAME"));
- setCellValue(sheet, 2 + i, 9, map.get("MOBILENUMB"));
- setCellValue(sheet, 2 + i, 10,map.get("OBJNAMES"));
- }
- private void setCellValue(Sheet sheet, int rownum, int cellnum, String value) {
- Cell cell = sheet.getRow(rownum).getCell(cellnum);
- cell.setCellValue(value);
- }
- private void writeToResponse(HttpServletResponse response, Workbook workbook, String name) throws IOException {
- // 修改模板内容导出新模板
- response.setContentType("application/x-msdownload");
- String fileNameURL = URLEncoder.encode(name, "UTF-8");
- response.setHeader("Content-disposition", "attachment;filename=" + fileNameURL + ";filename*=utf-8''" + fileNameURL);
- OutputStream out = response.getOutputStream();
- workbook.write(out);
- out.flush();
- out.close();
- }
- }
|