fix
songhuangfeng123
2022-09-20 f1f506172a3edff8d31e4db77b8940f115660919
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package com.gkhy.safePlatform.targetDuty.service.impl;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gkhy.safePlatform.targetDuty.excepiton.TargetDutyException;
import com.gkhy.safePlatform.targetDuty.model.dto.resp.TargetDutySummaryExcel;
import com.gkhy.safePlatform.targetDuty.repository.TargetDutySummaryRepository;
import com.gkhy.safePlatform.targetDuty.entity.TargetDutySummary;
import com.gkhy.safePlatform.targetDuty.service.CommonService;
import com.gkhy.safePlatform.targetDuty.service.TargetDutySummaryService;
import com.gkhy.safePlatform.targetDuty.service.baseService.TargetDutySummaryBaseService;
import com.gkhy.safePlatform.targetDuty.utils.DateUtils;
import com.gkhy.safePlatform.targetDuty.utils.poihelper.ExcelUtil;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.gkhy.safePlatform.commons.enums.ResultCodes;
import com.gkhy.safePlatform.commons.query.PageQuery;
import com.gkhy.safePlatform.commons.vo.ResultVO;
import com.gkhy.safePlatform.commons.vo.SearchResultVO;
import com.gkhy.safePlatform.targetDuty.model.dto.req.TargetDutySummaryQueryCriteria;
import com.gkhy.safePlatform.targetDuty.model.dto.resp.TargetDutySummaryDto;
import com.gkhy.safePlatform.targetDuty.utils.QueryHelpPlus;
import com.gkhy.safePlatform.commons.utils.BeanCopyUtils;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.*;
 
/**
 * (TargetDutySummary)表服务实现类
 *
 * @author xurui
 * @since 2022-07-21 15:35:14
 */
@Service("targetDutySummaryService")
public class TargetDutySummaryServiceImpl implements TargetDutySummaryService {
 
    @Autowired
    private TargetDutySummaryBaseService targetDutySummaryBaseService;
 
    @Resource
    private CommonService commonService;
 
    @Autowired
    public HttpServletResponse response;
    
    @Override
    public ResultVO queryAll(PageQuery<TargetDutySummaryQueryCriteria> pageQuery) {
        Long pageIndex = pageQuery.getPageIndex();
        Long pageSize = pageQuery.getPageSize();
        IPage<TargetDutySummary> page = new Page<>(pageIndex, pageSize);
 
        page = targetDutySummaryBaseService.selectPage(page,
                QueryHelpPlus.getPredicate(TargetDutySummary.class, pageQuery.getSearchParams()));
        List<TargetDutySummaryDto> respList = BeanCopyUtils.copyBeanList(page.getRecords(), TargetDutySummaryDto.class);
 
        // --------------------------- 获取部门信息-----------------------
        //收集所用到的部门ID
        Set<Long> collectDepIdSet = new HashSet();
        respList.forEach(f->{
            collectDepIdSet.add(f.getDepartmentId());
        });
        //获取部门名集合
        Map<Long,String> depNameMap = commonService.getDepName(collectDepIdSet);
 
        respList.forEach(f->{
            f.setDepartmentName(depNameMap.get(f.getDepartmentId()));
        });
 
        return new SearchResultVO<>(
                true,
                pageIndex,
                pageSize,page.getPages(),
                page.getTotal(),
                respList,
                ResultCodes.OK
        );
    }
 
 
    @Override
    public List<TargetDutySummary> queryAll(TargetDutySummaryQueryCriteria criteria) {
        return targetDutySummaryBaseService.queryAll( criteria);
    }
 
    @Override
    public void delete(Long[] ids) {
        if(ids == null){
            throw new TargetDutyException(ResultCodes.CLIENT_PARAM_ILLEGAL);
        }
        List<Long> idList = Arrays.asList(ids);
 
        List<TargetDutySummary> delList = new ArrayList<>();
        idList.forEach(f->{
            TargetDutySummary info = new TargetDutySummary();
            info.setDelFlag(1);
            info.setId(f);
            delList.add(info);
        });
        targetDutySummaryBaseService.updateBatchById(delList);
    }
 
    @Override
    public void exportData(TargetDutySummaryQueryCriteria queryCriteria)  throws IOException {
 
        Map<String,String> map = new LinkedHashMap<>();
        map.put("1","责任部门");
        map.put("2","安全目标指标");
        map.put("3","考核指标");
        map.put("4","1月");
        map.put("5","2月");
        map.put("6","3月");
        map.put("7","4月");
        map.put("8","5月");
        map.put("9","6月");
        map.put("10","7月");
        map.put("11","8月");
        map.put("12","9月");
        map.put("13","10月");
        map.put("14","11月");
        map.put("15","12月");
        map.put("16","考核结果");
 
        String key = DateUtils.date2String(new Date(), DateUtils.PATTERN_ALLTIME_NOSIGN) ;
        String fileName = URLEncoder.encode("目标汇总"+key+".xls", "UTF-8");
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xlsx");
        response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
 
 
        List<TargetDutySummaryExcel> respList = BeanCopyUtils.copyBeanList(this.queryAll(queryCriteria), TargetDutySummaryExcel.class);
 
        ExcelUtil.exportExcel(map,respList , response.getOutputStream(),DateUtils.PATTERN_STANDARD);
        response.getOutputStream().close();
    }
}