zhangf
2024-05-08 0414ddb0b2b3a7199ae6181a770f97ac140dbd73
goal-manage/goal-manage-service/src/main/java/com/gkhy/safePlatform/targetDuty/controller/TargetMngController.java
@@ -1,30 +1,44 @@
package com.gkhy.safePlatform.targetDuty.controller;
import java.util.Date;
import java.sql.Timestamp;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gkhy.safePlatform.targetDuty.entity.TargetDivideDetail;
import com.gkhy.safePlatform.targetDuty.entity.TargetMng;
import com.gkhy.safePlatform.targetDuty.service.TargetDivideDetailService;
import com.gkhy.safePlatform.targetDuty.service.TargetMngService;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import com.gkhy.safePlatform.commons.co.ContextCacheUser;
import com.gkhy.safePlatform.commons.enums.ResultCodes;
import com.gkhy.safePlatform.commons.query.PageQuery;
import com.gkhy.safePlatform.commons.utils.BeanCopyUtils;
import com.gkhy.safePlatform.commons.utils.PageUtils;
import com.gkhy.safePlatform.commons.vo.ResultVO;
import com.gkhy.safePlatform.commons.enums.ResultCodes;
import com.gkhy.safePlatform.targetDuty.entity.TargetDivideDetail;
import com.gkhy.safePlatform.targetDuty.entity.TargetMng;
import com.gkhy.safePlatform.targetDuty.enums.TargetDutyResultCodes;
import com.gkhy.safePlatform.targetDuty.enums.TargetMngLevelEnum;
import com.gkhy.safePlatform.targetDuty.excepiton.TargetDutyException;
import com.gkhy.safePlatform.targetDuty.model.dto.req.TargetCheckAndSubmitQueryCriteria;
import com.gkhy.safePlatform.targetDuty.model.dto.req.TargetMngImportExcel;
import com.gkhy.safePlatform.targetDuty.model.dto.req.TargetMngQueryCriteria;
import com.gkhy.safePlatform.targetDuty.model.dto.resp.TargetMngExcel;
import com.gkhy.safePlatform.targetDuty.service.TargetDivideDetailService;
import com.gkhy.safePlatform.targetDuty.service.TargetMngService;
import com.gkhy.safePlatform.targetDuty.service.baseService.TargetMngBaseService;
import com.gkhy.safePlatform.targetDuty.utils.DateUtils;
import com.gkhy.safePlatform.targetDuty.utils.poihelper.ExcelLogs;
import com.gkhy.safePlatform.targetDuty.utils.poihelper.ExcelUtil;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Serializable;
import java.net.URLEncoder;
import java.sql.Timestamp;
import java.util.*;
/**
 * 目标指标(TargetMng)表控制层
@@ -41,7 +55,13 @@
    @Resource
    private TargetMngService targetMngService;
    @Resource
    private TargetDivideDetailService targetDivideDetailService;
    private TargetMngBaseService targetMngBaseService;
    @Autowired
    public HttpServletRequest request;
    @Autowired
    public HttpServletResponse response;
    /**
@@ -52,11 +72,8 @@
     */
    @PostMapping(value = "/page/list")
    public ResultVO selectAll(@RequestBody PageQuery<TargetMngQueryCriteria> pageQuery){
        if(pageQuery.getSearchParams().getTargetType() == null){
            return new ResultVO<>(ResultCodes.CLIENT_PARAM_ILLEGAL,"缺少targetType");
        }
      PageUtils.checkCheck(pageQuery.getPageIndex(), pageQuery.getPageSize());
      return this.targetMngService.queryAll(pageQuery);
        return this.targetMngService.queryAll(pageQuery);
    }
@@ -80,15 +97,19 @@
    @PostMapping(value = "/addOrUpdate")
    public ResultVO update(@RequestBody TargetMng targetMng) {
        if (TargetMngLevelEnum.getByCode(targetMng.getLevel())==null){
            throw new TargetDutyException(TargetDutyResultCodes.TARGET_MNG_ENUM_LEVEL_NOT_EXIST);
        }
        if( !StringUtils.hasText(targetMng.getqName()) ||  !StringUtils.hasText(targetMng.getIndexNum())
                ||  !StringUtils.hasText(targetMng.getYear()) ||  !StringUtils.hasText(targetMng.getValue())
                ||  targetMng.getTargetType() == null){
            return new ResultVO<>(ResultCodes.CLIENT_PARAM_ILLEGAL,"缺少必填字段");
        }
        if (targetMng.getId() == null) {
            return new ResultVO<>(ResultCodes.OK,targetMngService.save(targetMng));
            return new ResultVO<>(ResultCodes.OK,targetMngBaseService.save(targetMng));
        } else {
            targetMngService.update(targetMng,new UpdateWrapper<TargetMng>().eq("id",targetMng.getId()));
            targetMngBaseService.update(targetMng,new UpdateWrapper<TargetMng>().eq("id",targetMng.getId()));
            return new ResultVO<>(ResultCodes.OK);
        }
    }
@@ -99,37 +120,68 @@
     * @param ids 主键结合
     * @return 删除结果
     */
    @GetMapping(value = "/delete")
    public ResultVO delete(String ids) {
       List<String> idList = Arrays.stream(ids.split(","))
                .collect(Collectors.toList());
       //删除关联表数据
        this.targetDivideDetailService.remove(new QueryWrapper<TargetDivideDetail>().in("target_id",idList));
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    public ResultVO delete(@RequestBody Long[] ids) {
        this.targetMngService.delete(ids);
        return new ResultVO<>(ResultCodes.OK);
    }
        this.targetMngService.removeByIds(idList);
    /**
     * 下载模板
     *
     */
    @GetMapping(value = "/exportTemplate")
    public void exportTemplate() throws IOException {
        targetMngService.exportTemplate();
    }
    /**
     * 导出一览数据
     *
     */
    @GetMapping(value = "/exportData")
    public void exportData(TargetMngQueryCriteria queryCriteria) throws IOException {
        targetMngService.exportData(queryCriteria);
    }
    /**
     * 导入数据
     *
     */
    @RequestMapping(value = "/importData")
    public ResultVO importData(MultipartFile file) throws IOException {
        targetMngService.importData(file);
        return new ResultVO<>(ResultCodes.OK);
    }
//    /**
//     * 导出
//     * @param response /
//     * @throws IOException /
//     */
//    public void download(HttpServletResponse response) throws IOException {
//        List<Map<String, Object>> list = new ArrayList<>();
//        for (OnlineUser user : all) {
//            Map<String, Object> map = new LinkedHashMap<>();
//            map.put("用户名", user.getUserName());
//            map.put("用户昵称", user.getNickName());
//            map.put("登录IP", user.getIp());
//            map.put("登录地点", user.getAddress());
//            map.put("浏览器", user.getBrowser());
//            map.put("登录日期", user.getLoginTime());
//            list.add(map);
//        }
//        FileUtil.downloadExcel(list, response);
//    }
    /**
     * 分页查询所有数据 -- 【目标检查上报页面】使用
     *
     * @param pageQuery 查询实体
     * @return 所有数据
     */
    @PostMapping(value = "/checkAndSubimt/list")
    public ResultVO list(Authentication authentication, @RequestBody PageQuery<TargetCheckAndSubmitQueryCriteria> pageQuery){
        if(pageQuery.getSearchParams().getRelateType() == null){
            return new ResultVO<>(ResultCodes.CLIENT_PARAM_ILLEGAL,"缺少targetType");
        }
        PageUtils.checkCheck(pageQuery);
        ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal();
        return this.targetMngService.queryAll(currentUser.getUid(),pageQuery);
    }
    /**
     * 统计
     *
     * @return 删除结果
     */
    @GetMapping(value = "/statistics")
    public ResultVO statistics(TargetMngQueryCriteria criteria) {
        return new ResultVO<>(ResultCodes.OK,this.targetMngService.statistics(criteria));
    }
    public static void main(String[] args) {
        TargetMng mng = new TargetMng();
@@ -137,7 +189,7 @@
        mng.setIndexNum("3");
        mng.setYear("2021");
        mng.setValue("312");
        mng.setLevel(1);
        mng.setLevel((byte)1);
        mng.setCompleteDate(new Timestamp(new java.util.Date().getTime()));
        mng.setMemo("发发发");
        mng.setTargetType(0);