kimi
2020-05-27 2893347bf72477c4d108e8589a0f61e3e97a990c
src/main/java/com/highdatas/mdm/controller/MaintainController.java
@@ -7,7 +7,6 @@
import com.baomidou.mybatisplus.plugins.Page;
import com.highdatas.mdm.entity.Flows;
import com.highdatas.mdm.entity.Maintain;
import com.highdatas.mdm.entity.MaintainDetail;
import com.highdatas.mdm.entity.TUser;
import com.highdatas.mdm.mapper.MaintainDetailMapper;
import com.highdatas.mdm.mapper.TableInfoMapper;
@@ -17,7 +16,6 @@
import com.highdatas.mdm.pojo.Result;
import com.highdatas.mdm.service.*;
import com.highdatas.mdm.util.Constant;
import com.highdatas.mdm.util.ContentBuilder;
import com.highdatas.mdm.util.DbUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -26,7 +24,6 @@
import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.text.MessageFormat;
import java.util.*;
import java.util.stream.Collectors;
@@ -34,7 +31,7 @@
 * <p>
 *  前端控制器
 * </p>
 *
 * @description 数据版本接口
 * @author kimi
 * @since 2019-12-16
 */
@@ -57,9 +54,16 @@
    @Autowired
    MaintainDetailMapper maintainDetailMapper;
    /**
     *
     * @description:  通过id获取版本信息
     * @param id maintainId
     * @return: maintain信息
     *
     */
    @RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
    public Result get(@PathVariable String id) {
        //通过id获取版本信息
        Maintain maintain = maintainService.selectById(id);
        if (maintain == null) {
            return Result.error(CodeMsg.SELECT_ERROR_NOTFOUND);
@@ -67,31 +71,59 @@
        return Result.success(maintain);
    }
    /**
     *
     * @description:  通过id 获取上个版本的相关数据
     * @param maintainId 版本id
     * @param id 数据id
     * @return: 上个版本的数据信息
     *
     */
    @RequestMapping(value = "/getPreInfo/{id}", method = RequestMethod.GET)
    public Result getPreInfo(@PathVariable String id, @RequestParam String maintainId) {
        //通过id获取版本信息
        Maintain maintain = maintainService.selectById(maintainId);
        if (maintain == null) {
            return Result.error(CodeMsg.SELECT_ERROR_NOTFOUND);
        }
        //通过id获取上个版本的数据信息
        Map<String, Object> preInfo = maintainService.getPreInfo(maintain, id);
        return Result.success(preInfo);
    }
    /**
     *
     * @description:  获取未提交的数据列表
     * @param tableName 表名
     * @param pageNo 页数
     * @return: 未提交数据
     *
     */
    @RequestMapping(value = "{tableName}/unSubmit/{pageNo}", method = RequestMethod.GET)
    public Result unSubmit(@PathVariable String tableName, @PathVariable Integer pageNo, HttpServletRequest request) throws UnsupportedEncodingException {
        //pageSize 每页数据量 , whereSegment筛选条件
        String pageSize = request.getParameter("pageSize");
        String whereSegment = request.getParameter("whereSegment");
        //请求头里获取用户信息
        TUser user = DbUtils.getUser(request);
        //获取筛选
        if (StringUtils.isEmpty(whereSegment)) {
            whereSegment = Constant.WHERE_DEFAULT;
        }else  {
            whereSegment = URLDecoder.decode(whereSegment, "UTF-8");
        }
        //获取未提交的数据
        return maintainService.getUnSubmitData(user, tableName, pageNo, pageSize, whereSegment);
    }
    /**
     *
     * @description:  获取未提交的数据量
     * @param tableName 表名
     * @return: 未提交数据量
     *
     */
    @RequestMapping(value = "{tableName}/unSubmitCnt", method = RequestMethod.GET)
    public Result unSubmitCnt(@PathVariable String tableName,HttpServletRequest request) throws UnsupportedEncodingException {
        //whereSegment 筛选条件
        String whereSegment = request.getParameter("whereSegment");
        TUser user = DbUtils.getUser(request);
        if (StringUtils.isEmpty(whereSegment)) {
@@ -99,34 +131,56 @@
        }else  {
            whereSegment = URLDecoder.decode(whereSegment, "UTF-8");
        }
        //获取未提交的数据量
        Long unSubmitDataCnt = maintainService.getUnSubmitDataCnt(user, tableName, whereSegment);
        return Result.success(unSubmitDataCnt);
    }
    /**
     *
     * @description:  获取未审批的数据量
     * @param tableName 表名
     * @return: 未审批数据量
     *
     */
    @RequestMapping(value = "{tableName}/unflowCnt", method = RequestMethod.GET)
    public Result unflow(@PathVariable String tableName,  HttpServletRequest request) throws UnsupportedEncodingException {
        //whereSegment 筛选条件
        String whereSegment = request.getParameter("whereSegment");
        TUser user = DbUtils.getUser(request);
        //组合筛选条件
        if (StringUtils.isEmpty(whereSegment)) {
            whereSegment = Constant.WHERE_DEFAULT;
        }else  {
            whereSegment = URLDecoder.decode(whereSegment, "UTF-8");
        }
        //获取未审批的数据条数
        Long invalidVerionDataCnt = maintainService.getInvalidVerionDataCnt(user, tableName, whereSegment);
        return Result.success(invalidVerionDataCnt);
    }
        @RequestMapping(value = "{tableName}/unflow/{pageNo}", method = RequestMethod.GET)
    /**
     *
     * @description:  获取未提交的数据列表
     * @param tableName 表名
     * @param pageNo 页数
     * @return: 未提交数据
     *
     */
    @RequestMapping(value = "{tableName}/unflow/{pageNo}", method = RequestMethod.GET)
    public Result unflow(@PathVariable String tableName, @PathVariable Integer pageNo, HttpServletRequest request) throws UnsupportedEncodingException {
        //pageSize 每页数据量 , whereSegment筛选条件
        String pageSize = request.getParameter("pageSize");
        String whereSegment = request.getParameter("whereSegment");
        //请求头里获取用户信息
        TUser user = DbUtils.getUser(request);
        //组装筛选条件
        if (StringUtils.isEmpty(whereSegment)) {
            whereSegment = Constant.WHERE_DEFAULT;
        }else  {
            whereSegment = URLDecoder.decode(whereSegment, "UTF-8");
        }
        //获取未审批通过的数据
        if (StringUtils.isEmpty(pageSize)) {
            return maintainService.getInvalidVerionData(user, tableName, whereSegment, pageNo, null);
        } else {
@@ -134,25 +188,36 @@
        }
    }
    /**
     *
     * @description:  获取主题的版本list
     * @param tableName 表名
     * @return: 主题的版本list
     *
     */
    @RequestMapping(value = "/version/{tableName}", method = RequestMethod.GET)
    public Result getHistory(@PathVariable String tableName, HttpServletRequest request) {
        //获取请求头里的用户信息
        TUser user = DbUtils.getUser(request);
        String userId = user.getUserId();
        //获取最大版本
        Maintain maxVersion = maintainService.getMaxVersion(tableName);
        if (maxVersion == null) {
            return Result.error(new CodeMsg(100001,"无当前版本"));
        }
        //获取当前版本
        Maintain nowVersion = maintainService.getNowVersion(tableName);
        //获取版本list
        List<Maintain> maintainList = maintainService.selectList(new EntityWrapper<Maintain>().eq("table_name", tableName).orderBy("order_no",false));
        List<Maintain> result = new ArrayList<>();
        int count = 0;
        for (Maintain maintain : maintainList) {
            String flowId = maintain.getFlowId();
            //去除未生效的版本
            if (StringUtils.isEmpty(flowId)) {
                continue;
            }
            //校验是否有权限
            boolean author = masterAuthorService.checkMaintainAuthor(user, maintain.getId());
            if (!author) {
                continue;
@@ -161,6 +226,7 @@
            if (flows.getStatus().equals(ActivitiStatus.close)) {
                continue;
            }
            //校验是否为下一节点审批人
            if (flows.getStatus().equals(ActivitiStatus.working) || flows.getStatus().equals(ActivitiStatus.refuse)) {
                boolean nextAudit = flowsService.isNextAudit(flows, userId);
                if (nextAudit) {
@@ -169,9 +235,11 @@
//                count++;
                continue;
            }else if(flows.getStatus().equals(ActivitiStatus.open)){
                //历史i版本状态为1
                maintain.setMaintainType(1);
            }
            if (nowVersion != null  && maintain.getId().equalsIgnoreCase(nowVersion.getId())) {
                //当前版本状态为0
                maintain.setMaintainType(0);
            }
            result.add(maintain);
@@ -180,6 +248,7 @@
        int cnt = maintainFieldService.getUnFlowCount(tableName, userId);
        count += cnt;
        if (count > 0) {
            //未生效版本状态为-1
            Maintain maintain = new Maintain();
            maintain.setMaintainType(-1);
            maintain.setVersion("待审核");
@@ -187,7 +256,7 @@
            maintain.setRecordCount(count);
            result.add(maintain);
        }
        //list 倒叙
        Collections.sort(result, new Comparator<Maintain>() {
            @Override
            public int compare(Maintain o1, Maintain o2) {
@@ -196,24 +265,40 @@
        });
        return Result.success(result);
}
//    /**
//     *
//     * @description:  获取主题的版本list
//     * @param tableName 表名
//     * @return: 主题的版本list
//     *
//     */
//    @RequestMapping(value = "/detail/{id}/{pageNo}", method = RequestMethod.GET)
//    public Result detail(@PathVariable String id, @PathVariable int pageNo) {
//        Maintain maintain = maintainService.selectById(id);
//        String tableName = maintain.getTableName();
//        String tableTempName = tableName + Constant.RECORD;
//
//        List<MaintainDetail> maintainDetailList = maintainDetailService.selectList(new EntityWrapper<MaintainDetail>().eq("parent_id", id));
//
//        return Result.success(maintain);
//    }
    @RequestMapping(value = "/detail/{id}/{pageNo}", method = RequestMethod.GET)
    public Result detail(@PathVariable String id, @PathVariable int pageNo) {
        Maintain maintain = maintainService.selectById(id);
        String tableName = maintain.getTableName();
        String tableTempName = tableName + Constant.RECORD;
        List<MaintainDetail> maintainDetailList = maintainDetailService.selectList(new EntityWrapper<MaintainDetail>().eq("parent_id", id));
        return Result.success(maintain);
    }
    /**
      *
      * @description:  获取所有版本的list
      * @param pageno yeshu
      * @return: 所有版本的list
      *
      */
    @RequestMapping(value = "/all/{pageno}", method = RequestMethod.GET)
    public Result all(@PathVariable int pageno, HttpServletRequest request) {
        //表名
        String tableName = request.getParameter("tableName");
        //检验表名是否存在
        String s = tableInfoMapper.selectTableByName(tableName);
        Page<Maintain> result;
        //pageSize 每页数据量
        String pageSize = request.getParameter("pageSize");
        Page<Maintain> maintainPage;
        if (StringUtils.isEmpty(pageSize)) {
@@ -222,6 +307,7 @@
        } else {
            maintainPage = new Page<Maintain>(pageno, Integer.valueOf(pageSize));
        }
        //筛选--表名
        if (StringUtils.isEmpty(tableName)) {
            result = maintainService.selectPage(maintainPage);
        } else {
@@ -233,6 +319,7 @@
        List<Maintain> resultObj = new ArrayList<>();
        for (Maintain record : records) {
            //校验是否审批结束
            String flowId = record.getFlowId();
            if (StringUtils.isEmpty(flowId)) {
                continue;
@@ -241,6 +328,7 @@
            if (flows == null || !flows.getStatus().equals(ActivitiStatus.open)) {
                continue;
            }
            //校验用户是否存在
            String chargeId = record.getChargeId();
            TUser user = DbUtils.getUserById(chargeId);
            if (user == null) {
@@ -255,18 +343,27 @@
        return  Result.success(result);
    }
    /**
     *
     * @description:  获取允许比较的版本list
     * @param pageNo 页数
     * @return: 允许比较的版本list
     *
     */
    @RequestMapping(value = "/compareList/{pageNo}", method = RequestMethod.GET)
    public Result compare(@PathVariable Integer pageNo, @RequestParam String tableName, HttpServletRequest request) {
        //pageSize 每页数据量
        String pageSizeStr = request.getParameter("pageSize");
        int pageSize = 15;
        if (!StringUtils.isEmpty(pageSizeStr)) {
            pageSize = Integer.valueOf(pageSizeStr);
        }
        //筛选掉不含流程信息后的版本list
        List<Maintain> maintainList = maintainService.selectList(new EntityWrapper<Maintain>().eq("table_name", tableName).isNotNull("flow_id").orderBy("order_no desc"));
        com.highdatas.mdm.pojo.Page page = new com.highdatas.mdm.pojo.Page(maintainList.size());
        page.setPageNo(pageNo);
        page.setPageSize(pageSize);
        //筛选审批成功的版本list,即当前生效的版本
        List<Maintain> collect = maintainList.stream().filter(maintain -> ActivitiStatus.open.equals(flowsService.getStatusByBusinessId(maintain.getId())))
                .skip(page.getBeginRecordNo_1()).limit(pageSize).collect(Collectors.toList());
@@ -283,11 +380,14 @@
            oneResult.put("userName", chargeId);
            oneResult.put("id", maintain.getId());
            if (user != null) {
                //添加用户信息
                oneResult.put("userName", user.getUserName());
            }
            if (i < collect.size() - 1) {
                //获取上个版本的版本信息
                Maintain preMaintain = collect.get(i + 1);
                //BY操作类型获取上个版本的数据量
                List<Map<String, Object>> maps = maintainDetailMapper.selectOperateCnt(maintain.getTableName(), preMaintain.getOrderNo(), maintain.getOrderNo());
                oneResult.put("content", maps);
@@ -299,6 +399,8 @@
            result.add(oneResult);
        }
        //组装返回值
        JSONObject object = new JSONObject();
        object.fluentPut("total", page.getRecordCount());
        object.fluentPut("size", page.getPageSize());
@@ -310,39 +412,56 @@
    }
    private String getOperateContent(List<Map<String, Object>> maps) {
        ContentBuilder builder = new ContentBuilder(Constant.EMPTY);
        for (Map<String, Object> map : maps) {
            Object operateObj = map.get(Constant.operate);
            Object cntObj = map.get(Constant.CNT);
            Operate operate= Operate.parse(operateObj.toString());
            String format = MessageFormat.format(operate.getLogMessage(), cntObj);
            builder.append(format);
        }
        return  builder.toString();
    }
    /**
     *
     * @description:  BY 操作类型获取比较两个版本的数据
     * @param pageNo 页数
     * @param operate 操作类型
     * @param maintainId1 第一个版本
     * @param maintainId2 第二个版本
     * @return: BY 操作类型返回数据
     *
     */
    @RequestMapping(value = "/compare/{maintainId1}/{maintainId2}", method = RequestMethod.GET)
    public Result compare(@PathVariable String maintainId1, @PathVariable String maintainId2, @RequestParam Operate operate, @RequestParam int pageNo, HttpServletRequest request) {
        //pageSize 每页数据量
        String pageSizeStr = request.getParameter("pageSize");
        int pageSize = 15;
        if (!StringUtils.isEmpty(pageSizeStr)) {
            pageSize = Integer.valueOf(pageSizeStr);
        }
        //比较两个版本
        JSONObject object = maintainService.compare(maintainId1, maintainId2, operate, pageNo, pageSize);
        return Result.success(object);
    }
    /**
     *
     * @description:  获取比较两个版本的字段
     * @param maintainId1 第一个版本
     * @param maintainId2 第二个版本
     * @return: 比较两个版本的字段
     *
     */
    @RequestMapping(value = "/compareField/{maintainId1}/{maintainId2}", method = RequestMethod.GET)
    public Result compareField(@PathVariable String maintainId1, @PathVariable String maintainId2) {
        //比较两个版本的字段
        JSONObject object = maintainService.compareField(maintainId1, maintainId2);
        return Result.success(object);
    }
    /**
     *
     * @description:  判断是否能继续上传表结构
     * @param tableName 表名
     * @return: 是否能继续上传表结构
     *
     */
    @RequestMapping(value = "/canUpload/{tableName}", method = RequestMethod.GET)
    public Result canUpload(@PathVariable String tableName) {
        //获取当前版本
        Maintain nowVersion = maintainService.getNowVersion(tableName);
        if (nowVersion == null) {
            return Result.success(true);
@@ -351,27 +470,47 @@
        }
    }
    /**
     *
     * @description:  获取某个版本下的记录
     * @param pageNo 页数
     * @return: 某个版本下的记录
     *
     */
    @RequestMapping(value = "/detail/{pageNo}", method = RequestMethod.GET)
    public Result setFlowId(@RequestParam String flowId,@PathVariable Integer pageNo, HttpServletRequest request) {
        //whereSegment 筛选条件
        String whereSegment = request.getParameter("whereSegment");
        //pageSize 每页数据量
        String pageSize = request.getParameter("pageSize");
        //获取请求头中的用户信息
        TUser user = DbUtils.getUser(request);
        if (StringUtils.isEmpty(whereSegment)) {
            whereSegment = Constant.WHERE_DEFAULT;
        }
        //通过筛选调教获取记录表中的数据
        if (StringUtils.isEmpty(pageSize)) {
            return maintainService.tempDataByVersionByFlow(user, flowId, whereSegment, pageNo, null);
        }
        return maintainService.tempDataByVersionByFlow(user, flowId, whereSegment, pageNo, Integer.valueOf(pageSize));
    }
    /**
     *
     * @description:  更新流程实例id
     * @param id 版本id
     * @param flowid 流程实例id
     * @return: 是否更新成功
     *
     */
    @RequestMapping(value = "/set/{id}", method = RequestMethod.GET)
    public Result setFlowId(@PathVariable String id, @RequestParam String flowid) {
        //通过id获取版本信息
        Maintain maintain = maintainService.selectById(id);
        if (maintain == null) {
            return Result.error(CodeMsg.SELECT_ERROR_NOTFOUND);
        }
        //更新流程实例id
        maintain.setFlowId(flowid);
        maintain.updateById();
        return Result.success(maintain);