|
|
@ -28,17 +28,13 @@ import com.elink.esua.epdc.commons.tools.utils.ConvertUtils; |
|
|
|
import com.elink.esua.epdc.commons.tools.constant.FieldConstant; |
|
|
|
import com.elink.esua.epdc.commons.tools.utils.Result; |
|
|
|
import com.elink.esua.epdc.constant.KpiFieldConstant; |
|
|
|
import com.elink.esua.epdc.dao.KpiFormulaDao; |
|
|
|
import com.elink.esua.epdc.dao.KpiRuleDao; |
|
|
|
import com.elink.esua.epdc.dao.KpiRuleParamDao; |
|
|
|
import com.elink.esua.epdc.dto.KpiRuleDTO; |
|
|
|
import com.elink.esua.epdc.dto.KpiRuleParamDTO; |
|
|
|
import com.elink.esua.epdc.dao.*; |
|
|
|
import com.elink.esua.epdc.dto.*; |
|
|
|
import com.elink.esua.epdc.dto.form.KpiRuleSaveOrUpdateFormDTO; |
|
|
|
import com.elink.esua.epdc.dto.result.KpiRuleQueryResultDTO; |
|
|
|
import com.elink.esua.epdc.entity.KpiFormulaEntity; |
|
|
|
import com.elink.esua.epdc.entity.KpiRuleEntity; |
|
|
|
import com.elink.esua.epdc.entity.KpiRuleParamEntity; |
|
|
|
import com.elink.esua.epdc.entity.*; |
|
|
|
import com.elink.esua.epdc.enums.KpiRuleModeEnum; |
|
|
|
import com.elink.esua.epdc.feign.AdminFeignClient; |
|
|
|
import com.elink.esua.epdc.service.KpiRuleService; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.slf4j.Logger; |
|
|
@ -46,10 +42,14 @@ import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.web.bind.annotation.PathVariable; |
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import javax.script.Invocable; |
|
|
|
import javax.script.ScriptEngine; |
|
|
|
import javax.script.ScriptEngineManager; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
/** |
|
|
|
* 考核规则表 |
|
|
@ -62,10 +62,19 @@ public class KpiRuleServiceImpl extends BaseServiceImpl<KpiRuleDao, KpiRuleEntit |
|
|
|
private Logger logger = LoggerFactory.getLogger(getClass()); |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private KpiRuleParamDao kpiRuleParamDao; |
|
|
|
private KpiRuleParamDao kpiRuleParamDao;//公式参数表
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
private KpiFormulaDao kpiFormulaDao; |
|
|
|
private KpiFormulaDao kpiFormulaDao;//绩效考核公式表
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
private KpiRuleDao kpiRuleDao; //考核规则表
|
|
|
|
@Autowired |
|
|
|
private KpiMetaDataDao kpiMetaDataDao; //绩效考核元数据表
|
|
|
|
@Autowired |
|
|
|
private AdminFeignClient adminFeignClient; |
|
|
|
@Autowired |
|
|
|
private KpiResultGridDao kpiResultGridDao; //网格考核最终得分表
|
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<KpiRuleDTO> page(Map<String, Object> params) { |
|
|
@ -269,6 +278,119 @@ public class KpiRuleServiceImpl extends BaseServiceImpl<KpiRuleDao, KpiRuleEntit |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result<List<KpiRuleDTO>> calcByRuleCode(String ruleCode) { |
|
|
|
return null; |
|
|
|
//每次JOB启动时,根据当前时间,获取上一个月的:月初-月末时间
|
|
|
|
Calendar c=Calendar.getInstance(); |
|
|
|
c.add(Calendar.MONTH, -1); |
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
int lastMonthMaxDay=c.getActualMaximum(Calendar.DAY_OF_MONTH); // 上月天数
|
|
|
|
c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), lastMonthMaxDay, 23, 59, 59); |
|
|
|
|
|
|
|
String gtimeEnd = sdf.format(c.getTime()); //按格式输出: 上月最后一天
|
|
|
|
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-01"); |
|
|
|
String gtimeStart = sdf2.format(c.getTime()); //按格式输出: 上月第一天
|
|
|
|
|
|
|
|
//查询考核规则表
|
|
|
|
KpiRuleDTO kpiRuleDTO = kpiRuleDao.queryKpiRuleMetaFormula(ruleCode); |
|
|
|
//根据 考核规则表-外键(公式id),查询绩效考核公式表,待运行公式方法
|
|
|
|
KpiFormulaDTO kpiFormulaDTO = kpiFormulaDao.queryFormula(kpiRuleDTO.getReferenceId()); |
|
|
|
//根据 考核规则表-主键,查询公式参数表,排序:1,2,3,4,5
|
|
|
|
List<KpiRuleParamDTO> kpiRuleParamDTO = kpiRuleParamDao.queryFormulaParam(kpiRuleDTO.getId()); |
|
|
|
|
|
|
|
int j = 0; |
|
|
|
while (true){ |
|
|
|
Result<List<Long>> departmentalList = adminFeignClient.pageDeptIdByTypeKey("grid_party",30,j+1); //得到所有的网格id
|
|
|
|
if (departmentalList.getData().size() > 0){ |
|
|
|
j++; |
|
|
|
for (int n = 0; n < departmentalList.getData().size(); n++) { |
|
|
|
int paramLength = 0; |
|
|
|
BigDecimal[] paramValue = new BigDecimal[kpiFormulaDTO.getParamAmount()]; |
|
|
|
Map<String, Object> map = new HashMap<String, Object>(); |
|
|
|
map.put("startDate",gtimeStart); |
|
|
|
map.put("endDate",gtimeEnd); |
|
|
|
map.put("deptId", departmentalList.getData().get(n).longValue()); |
|
|
|
for (int i = 0; i < kpiRuleParamDTO.size() ; i++) { //按照参数数量遍历
|
|
|
|
map.put("dataCode",kpiRuleParamDTO.get(i).getMetaDataCode()); |
|
|
|
KpiMetaDataDTO dataValue = kpiMetaDataDao.queryFormulaParamValue(map); //查询具体分值
|
|
|
|
if (dataValue != null) { |
|
|
|
paramValue[i] = dataValue.getDataValue(); |
|
|
|
paramLength++; |
|
|
|
} |
|
|
|
} |
|
|
|
if (paramLength == kpiFormulaDTO.getParamAmount()){ //参数准备完全时,执行js运算
|
|
|
|
BigDecimal workScore; |
|
|
|
try{ |
|
|
|
ScriptEngine engine = new ScriptEngineManager().getEngineByName("javascript");//获得一个javascipt的执行引擎
|
|
|
|
engine.eval(kpiFormulaDTO.getFormula()); //执行js代码:参数为:公式运行方法
|
|
|
|
boolean flag=engine instanceof Invocable;//是否可调用方法
|
|
|
|
if(!flag){ |
|
|
|
return new Result().error("运行方法异常"); |
|
|
|
}else{ |
|
|
|
Invocable in = (Invocable)engine; |
|
|
|
//执行js中的函数 参数:js方法名 + 参数
|
|
|
|
Double result=(Double) in.invokeFunction(kpiFormulaDTO.getFunctionName(), paramValue); |
|
|
|
Double workScoreDoouble = (double) Math.round(result*100)/100; |
|
|
|
workScore = new BigDecimal(workScoreDoouble); |
|
|
|
// 网格考核最终得分 表操作
|
|
|
|
KpiResultGridEntity kpiManualScoreEntity = new KpiResultGridEntity(); |
|
|
|
kpiManualScoreEntity.setWorkScore(workScore); |
|
|
|
kpiManualScoreEntity.setGridId(departmentalList.getData().get(n).longValue()); |
|
|
|
kpiManualScoreEntity.setStartDate(sdf2.parse(gtimeStart)); |
|
|
|
kpiManualScoreEntity.setEndDate(sdf2.parse(gtimeEnd)); |
|
|
|
kpiManualScoreEntity.setKpiCycle(kpiRuleDTO.getKpiCycle()); |
|
|
|
this.saveOrUpdateKpiResult(kpiManualScoreEntity); |
|
|
|
} |
|
|
|
}catch(Exception e){ |
|
|
|
e.printStackTrace(); |
|
|
|
return new Result().error("运行方法异常"+e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}else { |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
return new Result(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 更新或插入考核结果 |
|
|
|
* |
|
|
|
* @param kpiResultGridEntity : deptId, scoreStartDate, scoreEndDate, workScore |
|
|
|
* @return void |
|
|
|
* @author zhangyong |
|
|
|
* @date 2019/12/18 15:56 |
|
|
|
*/ |
|
|
|
private void saveOrUpdateKpiResult(KpiResultGridEntity kpiResultGridEntity) { |
|
|
|
//运算结果存储在 网格考核最终得分表 manual_score字段,:唯一性条件(deptId,scoreStartDate,scoreEndDate)
|
|
|
|
KpiResultGridDTO kpiResultGridDto = getKpiresultGrid(kpiResultGridEntity.getGridId(), kpiResultGridEntity.getStartDate(), kpiResultGridEntity.getEndDate()); |
|
|
|
Result<ParentAndAllDeptDTO> deptInfo = adminFeignClient.getParentAndAllDept(kpiResultGridEntity.getGridId().toString()); //查询部门信息
|
|
|
|
if (kpiResultGridDto != null) { //update
|
|
|
|
kpiResultGridEntity.setId(kpiResultGridDto.getId()); |
|
|
|
kpiResultGridDao.updateById(kpiResultGridEntity); |
|
|
|
}else { |
|
|
|
kpiResultGridEntity.setParentDeptIds(deptInfo.getData().getParentDeptIds()); |
|
|
|
kpiResultGridEntity.setParentDeptNames(deptInfo.getData().getParentDeptNames()); |
|
|
|
kpiResultGridEntity.setAllDeptIds(deptInfo.getData().getAllDeptIds()); |
|
|
|
kpiResultGridEntity.setAllDeptNames(deptInfo.getData().getAllDeptNames()); |
|
|
|
kpiResultGridDao.insert(kpiResultGridEntity); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询考核结果 |
|
|
|
* |
|
|
|
* @param deptId 部门id |
|
|
|
* @param stateDate 开始日期 |
|
|
|
* @param endDate 结束日期 |
|
|
|
* @return com.elink.esua.epdc.dto.KpiResultGridDTO |
|
|
|
* @author zy |
|
|
|
* @date 2019/12/19 15:56 |
|
|
|
*/ |
|
|
|
private KpiResultGridDTO getKpiresultGrid(Long deptId, Date stateDate, Date endDate) { |
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
map.put("deptId", deptId); |
|
|
|
map.put("scoreStartDate", stateDate); |
|
|
|
map.put("scoreEndDate", endDate); |
|
|
|
return kpiResultGridDao.selectManualScoringISExist(map); |
|
|
|
} |
|
|
|
} |
|
|
|