Browse Source

区直街道总规则计算

feature/dangjian
zhangyongzhangyong 6 years ago
parent
commit
3000e50134
  1. 122
      esua-epdc/epdc-module/epdc-kpi/epdc-kpi-client/src/main/java/com/elink/esua/epdc/dto/KpiResultSuperiorDTO.java
  2. 94
      esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/controller/KpiResultSuperiorController.java
  3. 33
      esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/dao/KpiResultSuperiorDao.java
  4. 92
      esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/entity/KpiResultSuperiorEntity.java
  5. 87
      esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/excel/KpiResultSuperiorExcel.java
  6. 47
      esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/redis/KpiResultSuperiorRedis.java
  7. 95
      esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/service/KpiResultSuperiorService.java
  8. 104
      esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/service/impl/KpiResultSuperiorServiceImpl.java
  9. 134
      esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/service/impl/KpiRuleServiceImpl.java
  10. 27
      esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/resources/mapper/KpiResultSuperiorDao.xml

122
esua-epdc/epdc-module/epdc-kpi/epdc-kpi-client/src/main/java/com/elink/esua/epdc/dto/KpiResultSuperiorDTO.java

@ -0,0 +1,122 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.elink.esua.epdc.dto;
import java.io.Serializable;
import java.util.Date;
import lombok.Data;
import java.math.BigDecimal;
/**
* 街道或区直绩效考核最终得分
*
* @author qu qu@elink-cn.com
* @since v1.0.0 2019-12-23
*/
@Data
public class KpiResultSuperiorDTO implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
private String id;
/**
* 网格ID
*/
private Long deptId;
/**
* 最终得分
*/
private BigDecimal finalScore;
/**
* 考核周期开始日
*/
private Date startDate;
/**
* 考核周期结束日
*/
private Date endDate;
/**
* 考核周期(字典值 代表月)
*/
private String kpiCycle;
/**
* 机构类别
*/
private String deptTypeKey;
/**
* 所有上级机构id
*/
private String parentDeptIds;
/**
* 所有上级机构名称
*/
private String parentDeptNames;
/**
* 所有机构id
*/
private String allDeptIds;
/**
* 所有机构名称
*/
private String allDeptNames;
/**
* 乐观锁
*/
private Integer revision;
/**
* 创建人
*/
private String createdBy;
/**
* 创建时间
*/
private Date createdTime;
/**
* 更新人
*/
private String updatedBy;
/**
* 更新时间
*/
private Date updatedTime;
/**
* 删除标记
*/
private String delFlag;
}

94
esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/controller/KpiResultSuperiorController.java

@ -0,0 +1,94 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.elink.esua.epdc.controller;
import com.elink.esua.epdc.commons.tools.page.PageData;
import com.elink.esua.epdc.commons.tools.utils.ExcelUtils;
import com.elink.esua.epdc.commons.tools.utils.Result;
import com.elink.esua.epdc.commons.tools.validator.AssertUtils;
import com.elink.esua.epdc.commons.tools.validator.ValidatorUtils;
import com.elink.esua.epdc.commons.tools.validator.group.AddGroup;
import com.elink.esua.epdc.commons.tools.validator.group.UpdateGroup;
import com.elink.esua.epdc.commons.tools.validator.group.DefaultGroup;
import com.elink.esua.epdc.dto.KpiResultSuperiorDTO;
import com.elink.esua.epdc.excel.KpiResultSuperiorExcel;
import com.elink.esua.epdc.service.KpiResultSuperiorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
/**
* 街道或区直绩效考核最终得分
*
* @author qu qu@elink-cn.com
* @since v1.0.0 2019-12-23
*/
@RestController
@RequestMapping("kpiresultsuperior")
public class KpiResultSuperiorController {
@Autowired
private KpiResultSuperiorService kpiResultSuperiorService;
@GetMapping("page")
public Result<PageData<KpiResultSuperiorDTO>> page(@RequestParam Map<String, Object> params){
PageData<KpiResultSuperiorDTO> page = kpiResultSuperiorService.page(params);
return new Result<PageData<KpiResultSuperiorDTO>>().ok(page);
}
@GetMapping("{id}")
public Result<KpiResultSuperiorDTO> get(@PathVariable("id") String id){
KpiResultSuperiorDTO data = kpiResultSuperiorService.get(id);
return new Result<KpiResultSuperiorDTO>().ok(data);
}
@PostMapping
public Result save(@RequestBody KpiResultSuperiorDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
kpiResultSuperiorService.save(dto);
return new Result();
}
@PutMapping
public Result update(@RequestBody KpiResultSuperiorDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
kpiResultSuperiorService.update(dto);
return new Result();
}
@DeleteMapping
public Result delete(@RequestBody String[] ids){
//效验数据
AssertUtils.isArrayEmpty(ids, "id");
kpiResultSuperiorService.delete(ids);
return new Result();
}
@GetMapping("export")
public void export(@RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
List<KpiResultSuperiorDTO> list = kpiResultSuperiorService.list(params);
ExcelUtils.exportExcelToTarget(response, null, list, KpiResultSuperiorExcel.class);
}
}

33
esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/dao/KpiResultSuperiorDao.java

@ -0,0 +1,33 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.elink.esua.epdc.dao;
import com.elink.esua.epdc.commons.mybatis.dao.BaseDao;
import com.elink.esua.epdc.entity.KpiResultSuperiorEntity;
import org.apache.ibatis.annotations.Mapper;
/**
* 街道或区直绩效考核最终得分
*
* @author qu qu@elink-cn.com
* @since v1.0.0 2019-12-23
*/
@Mapper
public interface KpiResultSuperiorDao extends BaseDao<KpiResultSuperiorEntity> {
}

92
esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/entity/KpiResultSuperiorEntity.java

@ -0,0 +1,92 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.elink.esua.epdc.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.elink.esua.epdc.commons.mybatis.entity.BaseEpdcEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.math.BigDecimal;
import java.util.Date;
/**
* 街道或区直绩效考核最终得分
*
* @author qu qu@elink-cn.com
* @since v1.0.0 2019-12-23
*/
@Data
@EqualsAndHashCode(callSuper=false)
@TableName("epdc_kpi_result_superior")
public class KpiResultSuperiorEntity extends BaseEpdcEntity {
private static final long serialVersionUID = 1L;
/**
* 网格ID
*/
private Long deptId;
/**
* 最终得分
*/
private BigDecimal finalScore;
/**
* 考核周期开始日
*/
private Date startDate;
/**
* 考核周期结束日
*/
private Date endDate;
/**
* 考核周期(字典值 代表月)
*/
private String kpiCycle;
/**
* 机构类别
*/
private String deptTypeKey;
/**
* 所有上级机构id
*/
private String parentDeptIds;
/**
* 所有上级机构名称
*/
private String parentDeptNames;
/**
* 所有机构id
*/
private String allDeptIds;
/**
* 所有机构名称
*/
private String allDeptNames;
}

87
esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/excel/KpiResultSuperiorExcel.java

@ -0,0 +1,87 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.elink.esua.epdc.excel;
import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
/**
* 街道或区直绩效考核最终得分
*
* @author qu qu@elink-cn.com
* @since v1.0.0 2019-12-23
*/
@Data
public class KpiResultSuperiorExcel {
@Excel(name = "主键")
private String id;
@Excel(name = "网格ID")
private Long deptId;
@Excel(name = "最终得分")
private BigDecimal finalScore;
@Excel(name = "考核周期开始日")
private Date startDate;
@Excel(name = "考核周期结束日")
private Date endDate;
@Excel(name = "考核周期(字典值 代表月,季,年)")
private String kpiCycle;
@Excel(name = "机构类别")
private String deptTypeKey;
@Excel(name = "所有上级机构id")
private String parentDeptIds;
@Excel(name = "所有上级机构名称")
private String parentDeptNames;
@Excel(name = "所有机构id")
private String allDeptIds;
@Excel(name = "所有机构名称")
private String allDeptNames;
@Excel(name = "乐观锁")
private Integer revision;
@Excel(name = "创建人")
private String createdBy;
@Excel(name = "创建时间")
private Date createdTime;
@Excel(name = "更新人")
private String updatedBy;
@Excel(name = "更新时间")
private Date updatedTime;
@Excel(name = "删除标记")
private String delFlag;
}

47
esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/redis/KpiResultSuperiorRedis.java

@ -0,0 +1,47 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.elink.esua.epdc.redis;
import com.elink.esua.epdc.commons.tools.redis.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* 街道或区直绩效考核最终得分
*
* @author qu qu@elink-cn.com
* @since v1.0.0 2019-12-23
*/
@Component
public class KpiResultSuperiorRedis {
@Autowired
private RedisUtils redisUtils;
public void delete(Object[] ids) {
}
public void set(){
}
public String get(String id){
return null;
}
}

95
esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/service/KpiResultSuperiorService.java

@ -0,0 +1,95 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.elink.esua.epdc.service;
import com.elink.esua.epdc.commons.mybatis.service.BaseService;
import com.elink.esua.epdc.commons.tools.page.PageData;
import com.elink.esua.epdc.dto.KpiResultSuperiorDTO;
import com.elink.esua.epdc.entity.KpiResultSuperiorEntity;
import java.util.List;
import java.util.Map;
/**
* 街道或区直绩效考核最终得分
*
* @author qu qu@elink-cn.com
* @since v1.0.0 2019-12-23
*/
public interface KpiResultSuperiorService extends BaseService<KpiResultSuperiorEntity> {
/**
* 默认分页
*
* @param params
* @return PageData<KpiResultSuperiorDTO>
* @author generator
* @date 2019-12-23
*/
PageData<KpiResultSuperiorDTO> page(Map<String, Object> params);
/**
* 默认查询
*
* @param params
* @return java.util.List<KpiResultSuperiorDTO>
* @author generator
* @date 2019-12-23
*/
List<KpiResultSuperiorDTO> list(Map<String, Object> params);
/**
* 单条查询
*
* @param id
* @return KpiResultSuperiorDTO
* @author generator
* @date 2019-12-23
*/
KpiResultSuperiorDTO get(String id);
/**
* 默认保存
*
* @param dto
* @return void
* @author generator
* @date 2019-12-23
*/
void save(KpiResultSuperiorDTO dto);
/**
* 默认更新
*
* @param dto
* @return void
* @author generator
* @date 2019-12-23
*/
void update(KpiResultSuperiorDTO dto);
/**
* 批量删除
*
* @param ids
* @return void
* @author generator
* @date 2019-12-23
*/
void delete(String[] ids);
}

104
esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/service/impl/KpiResultSuperiorServiceImpl.java

@ -0,0 +1,104 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.elink.esua.epdc.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl;
import com.elink.esua.epdc.commons.tools.page.PageData;
import com.elink.esua.epdc.commons.tools.utils.ConvertUtils;
import com.elink.esua.epdc.commons.tools.constant.FieldConstant;
import com.elink.esua.epdc.dao.KpiResultSuperiorDao;
import com.elink.esua.epdc.dto.KpiResultSuperiorDTO;
import com.elink.esua.epdc.entity.KpiResultSuperiorEntity;
import com.elink.esua.epdc.redis.KpiResultSuperiorRedis;
import com.elink.esua.epdc.service.KpiResultSuperiorService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* 街道或区直绩效考核最终得分
*
* @author qu qu@elink-cn.com
* @since v1.0.0 2019-12-23
*/
@Service
public class KpiResultSuperiorServiceImpl extends BaseServiceImpl<KpiResultSuperiorDao, KpiResultSuperiorEntity> implements KpiResultSuperiorService {
@Autowired
private KpiResultSuperiorRedis kpiResultSuperiorRedis;
@Override
public PageData<KpiResultSuperiorDTO> page(Map<String, Object> params) {
IPage<KpiResultSuperiorEntity> page = baseDao.selectPage(
getPage(params, FieldConstant.CREATED_TIME, false),
getWrapper(params)
);
return getPageData(page, KpiResultSuperiorDTO.class);
}
@Override
public List<KpiResultSuperiorDTO> list(Map<String, Object> params) {
List<KpiResultSuperiorEntity> entityList = baseDao.selectList(getWrapper(params));
return ConvertUtils.sourceToTarget(entityList, KpiResultSuperiorDTO.class);
}
private QueryWrapper<KpiResultSuperiorEntity> getWrapper(Map<String, Object> params){
String id = (String)params.get(FieldConstant.ID_HUMP);
QueryWrapper<KpiResultSuperiorEntity> wrapper = new QueryWrapper<>();
wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id);
return wrapper;
}
@Override
public KpiResultSuperiorDTO get(String id) {
KpiResultSuperiorEntity entity = baseDao.selectById(id);
return ConvertUtils.sourceToTarget(entity, KpiResultSuperiorDTO.class);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void save(KpiResultSuperiorDTO dto) {
KpiResultSuperiorEntity entity = ConvertUtils.sourceToTarget(dto, KpiResultSuperiorEntity.class);
insert(entity);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(KpiResultSuperiorDTO dto) {
KpiResultSuperiorEntity entity = ConvertUtils.sourceToTarget(dto, KpiResultSuperiorEntity.class);
updateById(entity);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(String[] ids) {
// 逻辑删除(@TableLogic 注解)
baseDao.deleteBatchIds(Arrays.asList(ids));
}
}

134
esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/service/impl/KpiRuleServiceImpl.java

@ -82,6 +82,9 @@ public class KpiRuleServiceImpl extends BaseServiceImpl<KpiRuleDao, KpiRuleEntit
private KpiResultGridDao kpiResultGridDao; private KpiResultGridDao kpiResultGridDao;
@Autowired @Autowired
private DeptUtils deptUtils; private DeptUtils deptUtils;
//网格考核最终得分
@Autowired
private KpiResultSuperiorDao kpiResultSuperiorDao;
@Override @Override
public PageData<KpiRuleDTO> page(Map<String, Object> params) { public PageData<KpiRuleDTO> page(Map<String, Object> params) {
@ -289,6 +292,8 @@ public class KpiRuleServiceImpl extends BaseServiceImpl<KpiRuleDao, KpiRuleEntit
return this.calcWorkScoreByRuleCode(ruleCode); return this.calcWorkScoreByRuleCode(ruleCode);
}else if ("calcBaseGridFinalScore".equals(ruleCode)){ //计算 计算基础网格月度、季度、年度总得分 }else if ("calcBaseGridFinalScore".equals(ruleCode)){ //计算 计算基础网格月度、季度、年度总得分
return this.calcBaseGridFinalScoreByRuleCode(ruleCode); return this.calcBaseGridFinalScoreByRuleCode(ruleCode);
}else if ("calcDistrictStreetGeneralRule".equals(ruleCode)){ //计算区直/街道考核最终得分(总规则)
return this.calcDistrictStreetGeneralRule(ruleCode);
} }
return new Result(); return new Result();
} }
@ -493,4 +498,133 @@ public class KpiRuleServiceImpl extends BaseServiceImpl<KpiRuleDao, KpiRuleEntit
map.put("scoreEndDate", endDate); map.put("scoreEndDate", endDate);
return kpiResultGridDao.selectManualScoringISExist(map); return kpiResultGridDao.selectManualScoringISExist(map);
} }
/**
* @Description: 计算区直/街道考核最终得分(总规则)
* @Param: [ruleCode]
* @return: com.elink.esua.epdc.commons.tools.utils.Result
* @Author: zy
* @Date: 2019-12-23
*/
public Result calcDistrictStreetGeneralRule(String ruleCode){
KpiResultSuperiorEntity kpiResultSuperiorEntity = new KpiResultSuperiorEntity();
KpiRuleDTO kpiRuleDTO = kpiRuleDao.queryKpiRuleMetaFormula(ruleCode);// 查询考核规则表
YearMonth now = YearMonth.now();
Date endDate = LocalDateUtils.localDateToDate(now.minusMonths(NumConstant.ONE).atEndOfMonth());
// 考核周期
String kpiCycle = kpiRuleDTO.getKpiCycle();
// 考核结束日
kpiResultSuperiorEntity.setEndDate(endDate);
// 考核开始日
if (kpiCycle.equals(KpiCycleEnum.KPI_CYCLE_MONTH.getValue())) {
kpiResultSuperiorEntity.setStartDate(LocalDateUtils.localDateToDate(now.minusMonths(NumConstant.ONE).atDay(NumConstant.ONE)));
} else if (kpiCycle.equals(KpiCycleEnum.KPI_CYCLE_QUARTER.getValue())) {
kpiResultSuperiorEntity.setStartDate(LocalDateUtils.localDateToDate(now.minusMonths(NumConstant.THREE).atDay(NumConstant.ONE)));
} else if (kpiCycle.equals(KpiCycleEnum.KPI_CYCLE_YEAR.getValue())) {
kpiResultSuperiorEntity.setStartDate(LocalDateUtils.localDateToDate(now.minusMonths(NumConstant.ELEVEN).atDay(NumConstant.ONE)));
}
kpiResultSuperiorEntity.setKpiCycle(kpiCycle);
// 根据 考核规则表-主键,查询公式参数表,排序:1,2,3,4,5
List<KpiRuleParamDTO> ruleParamList = kpiRuleParamDao.queryFormulaParam(kpiRuleDTO.getId());
List<String> metaDateCodeList = Lists.newArrayList();
for (int i = 0; i < ruleParamList.size(); i++) {
metaDateCodeList.add(ruleParamList.get(i).getMetaDataCode());
}
//区 考核最终得分计算
this.assessmentScoreCalculation(kpiRuleDTO.getReferenceId(),
kpiResultSuperiorEntity.getStartDate(),kpiResultSuperiorEntity.getEndDate(),
metaDateCodeList,OrganizationTypeConstant.ORG_TYPE_DISTRICT_DEPT,kpiCycle);
//街区 考核最终得分计算
this.assessmentScoreCalculation(kpiRuleDTO.getReferenceId(),
kpiResultSuperiorEntity.getStartDate(),kpiResultSuperiorEntity.getEndDate(),
metaDateCodeList,OrganizationTypeConstant.ORG_TYPE_STREET_DEPT,kpiCycle);
return new Result();
}
/**
* @Description: 根据 区直/街道考核最终得分 JS函数得出总数
* @Param: [referenceId] 考核规则表:公式ID
* metaDateCodeList 公式参数表元数据编码
* startDate 考核开始时间
* endDate 考核结束时间
* typeKey 部门类型
* String kpiCycle 考核周期
* @return: BigDecimal
* @Author: zy
* @Date: 2019-12-23
*/
public Result assessmentScoreCalculation(String referenceId,Date startDate, Date endDate,List<String> metaDateCodeList,String typeKey,String kpiCycle){
// 根据 考核规则表-外键(公式id),查询绩效考核公式表,待运行公式方法
KpiFormulaDTO kpiFormulaDTO = kpiFormulaDao.queryFormula(referenceId);
int pageSize = NumConstant.THIRTY;
int pageIndex = NumConstant.ONE;
List<Long> deptIdList = deptUtils.getDeptIdList(typeKey, pageSize, pageIndex);
do {
for (Long deptId : deptIdList) {
BigDecimal[] paramValue = selectArrayOfMetaDate(deptId, startDate, endDate, metaDateCodeList);
//参数准备完全时,执行js运算
if (paramValue.length == kpiFormulaDTO.getParamAmount()) {
BigDecimal calculationScore;
Result<BigDecimal> score = this.runJavaScriptFunction(kpiFormulaDTO,paramValue);
calculationScore = score.getData();
//插入到:街道或区直绩效考核最终得分表
DeptLevelAndLeaderDTO deptLevelInfo = deptUtils.getDeptLevelInfo(deptId, YesOrNoEnum.YES);
KpiResultSuperiorEntity kpiResultSuperiorEntity = new KpiResultSuperiorEntity();
kpiResultSuperiorEntity.setStartDate(startDate);
kpiResultSuperiorEntity.setEndDate(endDate);
kpiResultSuperiorEntity.setKpiCycle(kpiCycle);
kpiResultSuperiorEntity.setFinalScore(calculationScore);
kpiResultSuperiorEntity.setDeptId(deptId);
kpiResultSuperiorEntity.setDeptTypeKey(typeKey);
kpiResultSuperiorEntity.setParentDeptIds(deptLevelInfo.getParentDeptIds());
kpiResultSuperiorEntity.setParentDeptNames(deptLevelInfo.getParentDeptNames());
kpiResultSuperiorEntity.setAllDeptIds(deptLevelInfo.getAllDeptIds());
kpiResultSuperiorEntity.setAllDeptNames(deptLevelInfo.getAllDeptNames());
kpiResultSuperiorDao.insert(kpiResultSuperiorEntity);
}
}
pageIndex++;
deptIdList = deptUtils.getDeptIdList(typeKey, pageSize, pageIndex);
} while (CollUtil.isNotEmpty(deptIdList));
return new Result();
}
/**
* @Description: js函数运行
* @Param: [kpiFormulaDTO, paramValue]
* @return: com.elink.esua.epdc.commons.tools.utils.Result<BigDecimal>
* @Author: zy
* @Date: 2019-12-23
*/
public Result<BigDecimal> runJavaScriptFunction(KpiFormulaDTO kpiFormulaDTO,BigDecimal[] paramValue){
BigDecimal calculationScore = new BigDecimal(0);
try {
//获得一个javascipt的执行引擎
ScriptEngine engine = new ScriptEngineManager().getEngineByName("javascript");
//执行js代码:参数为:公式运行方法
engine.eval(kpiFormulaDTO.getFormula());
//是否可调用方法
boolean flag = engine instanceof Invocable;
if (!flag) {
return new Result().error("运行方法异常");
}
Invocable in = (Invocable) engine;
//执行js中的函数 参数:js方法名 + 参数
Double result = (Double) in.invokeFunction(kpiFormulaDTO.getFunctionName(), paramValue);
Double workScoreDoouble = (double) Math.round(result * 100) / 100;
calculationScore = new BigDecimal(workScoreDoouble);
} catch (Exception e) {
e.printStackTrace();
return new Result().error("运行方法异常" + e.getMessage());
}
return new Result().ok(calculationScore);
}
} }

27
esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/resources/mapper/KpiResultSuperiorDao.xml

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.elink.esua.epdc.dao.KpiResultSuperiorDao">
<resultMap type="com.elink.esua.epdc.entity.KpiResultSuperiorEntity" id="kpiResultSuperiorMap">
<result property="id" column="ID"/>
<result property="deptId" column="dept_id"/>
<result property="finalScore" column="final_score"/>
<result property="startDate" column="start_date"/>
<result property="endDate" column="end_date"/>
<result property="kpiCycle" column="kpi_cycle"/>
<result property="deptTypeKey" column="dept_type_key"/>
<result property="parentDeptIds" column="parent_dept_ids"/>
<result property="parentDeptNames" column="parent_dept_names"/>
<result property="allDeptIds" column="all_dept_ids"/>
<result property="allDeptNames" column="all_dept_names"/>
<result property="revision" column="REVISION"/>
<result property="createdBy" column="CREATED_BY"/>
<result property="createdTime" column="CREATED_TIME"/>
<result property="updatedBy" column="UPDATED_BY"/>
<result property="updatedTime" column="UPDATED_TIME"/>
<result property="delFlag" column="DEL_FLAG"/>
</resultMap>
</mapper>
Loading…
Cancel
Save