cjl
2025-01-06 27e6bc3df3e39e0d0b147b155a89ad6837ea972b
screen-api/src/main/java/com/moral/api/controller/AllocationController.java
@@ -1,47 +1,62 @@
package com.moral.api.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.moral.api.entity.AllocationLog;
import com.moral.api.entity.ResponsibilityUnit;
import com.moral.api.pojo.enums.AllocationApproveEnum;
import com.moral.api.pojo.enums.ChangeEnum;
import com.moral.api.pojo.enums.YesOrNo;
import com.moral.api.pojo.ext.allocation.AllocationExcelExt;
import com.moral.api.pojo.ext.allocation.AllocationExt;
import com.moral.api.pojo.ext.allocation.AllocationPageExt;
import com.moral.api.pojo.query.ResponsibilityUnitQuery;
import com.moral.api.pojo.query.allocation.*;
import com.moral.api.pojo.query.allocationextension.AllocationExtensionAddCond;
import com.moral.api.pojo.vo.allocation.AllocationListExcelVo;
import com.moral.api.pojo.vo.allocation.AllocationPageVo;
import com.moral.api.pojo.vo.allocation.AllocationVo;
import com.moral.api.pojo.vo.file.FileAddressVo;
import com.moral.api.service.AllocationService;
import com.moral.api.service.ResponsibilityUnitService;
import com.moral.api.utils.*;
import com.moral.constant.Constants;
import com.moral.constant.PageResult;
import com.moral.constant.ResultMessage;
import com.moral.util.DateUtils;
import com.moral.util.WebUtils;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.aspectj.apache.bcel.generic.RET;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.moral.api.entity.Allocation;
import com.moral.api.entity.ResponsibilityUnit;
import com.moral.api.pojo.dto.allocation.AllocationUnitViewDto;
import com.moral.api.service.AllocationService;
import com.moral.api.utils.EasyExcelUtils;
import com.moral.api.utils.NoModelWriteData;
import com.moral.constant.Constants;
import com.moral.constant.ResultMessage;
import com.moral.util.WebUtils;
import javax.validation.Valid;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
@Api(tags = {"立行立改"})
@RestController
@RequestMapping("allocation")
@Slf4j
public class AllocationController {
    @Value("${file.path}")
    private String basePath;
    @Autowired
    private AllocationService allocationService;
    @Autowired
    private ResponsibilityUnitService responsibilityUnitService;
    @ApiOperation(value = "污染类型", notes = "污染类型")
@@ -54,10 +69,6 @@
        return ResultMessage.ok(professions);
    }
    @ApiOperation(value = "责任单位", notes = "责任单位")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
@@ -68,46 +79,89 @@
        return ResultMessage.ok(responsibilityUnits);
    }
    /**
     * 添加交办单
     * @return
     */
    @PostMapping("insert")
    public  ResultMessage insert(@RequestBody Allocation allocation){
    @ApiOperation("新增")
    public  ResultMessage insert(@Valid @RequestBody AllocationAddCond allocation){
        allocationService.insertAllocation(allocation);
        return ResultMessage.ok();
    }
    /**
     * 查看交办单
     * @return
     */
    @GetMapping("check")
    public ResultMessage check(Integer id){
        allocationService.check(id);
        return ResultMessage.ok();
    }
    /**
     * 修改表单
     * @param allocation
     * @param allocationUpdateCond
     * @return
     *
     *
     */
    @PostMapping("update")
    public ResultMessage update(@RequestBody Allocation allocation){
        allocationService.updateAll(allocation);
    @ApiOperation("修改")
    public ResultMessage update(@Valid @RequestBody AllocationUpdateCond allocationUpdateCond){
        allocationService.updateAll(allocationUpdateCond);
        return ResultMessage.ok();
    }
    /**
     * 根据条件查询
     * @return
     */
    @GetMapping("selectAll")
    public ResultMessage selectAll(Map<String,Object> map){
        allocationService.selectAll(map);
    @PostMapping("change")
    @ApiOperation("整改")
    public ResultMessage changeAllocation(@Valid @RequestBody AllocationChangeCond changeCond){
        allocationService.changeAllocation(changeCond);
        return ResultMessage.ok();
    }
    @PostMapping("check")
    @ApiOperation("审批")
    public ResultMessage checkAllocation(@Valid @RequestBody AllocationCheckCond checkCond){
        allocationService.checkAllocation(checkCond);
        return ResultMessage.ok();
    }
    @PostMapping("/page")
    @ApiOperation("分页")
    public ResultMessage<PageResult<AllocationPageVo>> page(@Valid @RequestBody AllocationPageCond allocationPageCond) {
        Page<AllocationPageExt> page = allocationService.extPage(allocationPageCond);
        PageResult<AllocationPageVo> result = new PageResult<>(page);
        result.setList(AllocationPageVo.convert(page.getRecords()));
        return ResultMessage.ok(result);
    }
    @GetMapping("/detail")
    @ApiOperation("详情")
    public ResultMessage<AllocationVo> get(Integer id) {
        AllocationExt allocationext = allocationService.extOne(id);
        AllocationVo allocationVo = AllocationVo.convert(allocationext);
        allocationVo.setFileBaseList(allocationext.getFileBaseList());
        allocationVo.setFileChangeList(allocationext.getFileChangeList());
        allocationVo.setFileApproveList(allocationext.getFileApproveList());
        allocationVo.setApproveList(allocationext.getApproveList());
        allocationVo.setTime(DateUtils.dateToDateString(allocationVo.getEscalationTime(), DateUtils.yyyy_MM_dd_CN));
        return ResultMessage.ok(allocationVo);
    }
    @GetMapping("remove")
    @ApiOperation("删除")
    public ResultMessage removeById(Integer id){
        allocationService.removeById(id);
        return ResultMessage.ok();
    }
    @GetMapping("invalid")
    @ApiOperation("作废")
    public ResultMessage invalidResult(@RequestParam @ApiParam(value = "id",name = "主键id") Integer id,
                                       @RequestParam @ApiParam(value = "invalidReason",name = "作废理由") String invalidReason){
        allocationService.invalidResult(id,invalidReason);
        return ResultMessage.ok();
    }
    @PostMapping("/applyfor")
    @ApiOperation("申请延期")
    public ResultMessage applyFor(@Valid @RequestBody AllocationExtensionAddCond allocationExtensionAddCond) {
        return allocationService.applyFor(allocationExtensionAddCond) ? ResultMessage.ok() : ResultMessage.fail();
    }
@@ -116,26 +170,18 @@
     * @return
     */
    @GetMapping("selectUnitView")
    @ApiOperation("表单总览")
    public ResultMessage selectUnitView(HttpServletRequest request){
        Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
        Map<String, Object> map1 = allocationService.selectUnitView(params);
        return ResultMessage.ok(map1);
        return ResultMessage.ok(ObjectUtils.isEmpty(map1)? "0":map1);
    }
    @GetMapping("unitExel")
    public void unitExel(HttpServletResponse response,HttpServletRequest request){
        Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
        //数据集合
        Map<String, Object> map1 = allocationService.selectUnitView(params);
        List<AllocationUnitViewDto> unitView = (List<AllocationUnitViewDto>) map1.get("unitView");
        ArrayList<Map<String, Object>> mapArrayList = new ArrayList<>();
        for (AllocationUnitViewDto allocationUnitViewDto : unitView) {
            Map<String, Object> map = entityToMap(allocationUnitViewDto);
            mapArrayList.add(map);
        }
        List<Map<String, Object>> mapArrayList = allocationService.unitExel(params);
        if (CollectionUtils.isEmpty(mapArrayList)) {
            return;
        }
@@ -159,22 +205,87 @@
        }
    }
    /**
     实体类转Map
     */
    public static Map<String, Object> entityToMap(Object object) {
        Map<String, Object> map = new HashMap<>();
        for (Field field : object.getClass().getDeclaredFields()) {
            try {
                boolean flag = field.isAccessible();
                field.setAccessible(true);
                Object o = field.get(object);
                map.put(field.getName(), o);
                field.setAccessible(flag);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return map;
    @GetMapping("updataUnit")
    @ApiOperation("修改责任单位")
    public ResultMessage updataUnit(@RequestParam @ApiParam(value = "id",name = "主键id") Integer id,
                                    @RequestParam @ApiParam(value = "unitId",name = "责任主题Id") Integer unitId,
                                    @RequestParam @ApiParam(value = "polluteType",name = "污染分类Id") Integer polluteType){
        allocationService.updataUnit(id,unitId,polluteType);
        return ResultMessage.ok();
    }
    @GetMapping("getLog")
    @ApiOperation("修改记录")
    public ResultMessage getLog(@RequestParam @ApiParam(value = "allocationNum",name = "责任单号") String allocationNum){
        List<AllocationLog> log = allocationService.getLog(allocationNum);
        return ResultMessage.ok(log);
    }
    @GetMapping("listExcel")
    @ApiOperation("批量导出")
    public void listExcel(@RequestParam @ApiParam(value = "id",name = "主键id") List<Integer> id,HttpServletResponse response){
        List<AllocationExcelExt> extList = allocationService.listExcel(id);
        try {
            genImageExcel(extList,response);
        }catch (Exception e){
            log.error("error result ",e);
        }
    }
    private void genImageExcel(List<AllocationExcelExt> list, HttpServletResponse response) throws IOException {
        if (CollectionUtils.isEmpty(list)) {
            return;
        }
        List<AllocationListExcelVo> demoDataList = new ArrayList<>();
        for(int i = 0;i<list.size();i++){
            AllocationExcelExt excelExt = list.get(i);
            AllocationListExcelVo item = AllocationListExcelVo.convert(excelExt);
            String stateStr = Objects.nonNull(excelExt.getState())?AllocationApproveEnum.getByValue(excelExt.getState()).getName():"未找到状态";
            item.setStateStr(stateStr);
            List<String> urls = new ArrayList<>();
            for(FileAddressVo z : excelExt.getFileBaseList()){
                urls.add(handleFileRealPath(z.getFileAddress()));
            }
            item.setChangeTypeStr(Objects.isNull(excelExt.getChangeType())?" ":ChangeEnum.getByValue(excelExt.getChangeType()).getName());
            item.setChangeStr(Objects.isNull(excelExt.getIsChange())?"否": YesOrNo.getByValue(excelExt.getIsChange()).getName());
            item.setWriteCellDataFile(urls);
            List<String> urlsAfter = new ArrayList<>();
            for(FileAddressVo z : excelExt.getFileChangeList()){
                urlsAfter.add(handleFileRealPath(z.getFileAddress()));
            }
            item.setWriteCellDataFileResult(urlsAfter);
            item.setEscalationTimeStr(DateUtils.dateToDateString(excelExt.getEscalationTime(),DateUtils.yyyy_MM_dd_EN));
            item.setChangeTimeStr(Objects.isNull(excelExt.getChangeTime())?" ":DateUtils.dateToDateString(excelExt.getChangeTime(),DateUtils.yyyy_MM_dd_EN));
            demoDataList.add(item);
        }
        try {
            response.setHeader("Content-disposition", "attachment;filename*=utf-8''"
                    + URLEncoder.encode("交办单导出", "utf-8") + ".xlsx");
            response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
        EasyExcel.write(response.getOutputStream(), AllocationListExcelVo.class)
                .registerWriteHandler(new CustomImageModifyHandler()).sheet("交办单").doWrite(demoDataList);
            response.getOutputStream().close();
        }catch (Exception e){
            log.error("error result ",e);
        }
    }
    private String handleFileRealPath(String path) {
        return basePath.replaceAll(StringUtils.BACKSLASH.concat(StringUtils.BACKSLASH), StringUtils.SLASH).concat(StringUtils.SLASH).concat(path);
    }
    @GetMapping("unitQuery")
    @ApiOperation("显示责任主体")
    public ResultMessage unitQuery(){
        List<ResponsibilityUnitQuery> responsibilityUnitQueries = responsibilityUnitService.unitQuery();
        return ResultMessage.ok(responsibilityUnitQueries);
    }
}