Commit 24cdb527 authored by 赵啸非's avatar 赵啸非

添加规则编码实现

parent 61ab114c
package com.mortals.xhx.busiz.req;
import com.mortals.xhx.busiz.BaseReq;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
@Data
public class PerformSaveReq extends BaseReq {
/**
* 工号
*/
private String workNum;
/**
* 标题
*/
private String title;
/**
* 扣分时间
*/
private Date happenTime;
/**
* 规则编码
*/
private String ruleCode;
/**
* 类型
*/
private String performType;
}
package com.mortals.xhx.busiz.web;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.exception.AppException;
import com.mortals.xhx.base.framework.annotation.ApiUserAuth;
import com.mortals.xhx.busiz.req.PerformReq;
import com.mortals.xhx.busiz.req.PerformSaveReq;
import com.mortals.xhx.busiz.rsp.ApiResp;
import com.mortals.xhx.common.code.ApiRespCodeEnum;
import com.mortals.xhx.common.code.PerformTypeEnum;
import com.mortals.xhx.module.perform.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
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.RestController;
import javax.servlet.http.HttpServletRequest;
@RestController
@Slf4j
@RequestMapping("/api/v1/web/perform")
public class ApiWebPerformController extends AbstractBaseController<PerformReq> {
@Autowired
private PerformAttendRecordService attendRecordService;
@Autowired
private PerformReviewRecordService reviewRecordService;
@Autowired
private PerformComplainRecordService complainRecordService;
@Autowired
private PerformGoworkRecordService performGoworkRecordService;
@Autowired
private PerformEffectRecordService effectRecordService;
@Autowired
private PerformOtherRecordService otherRecordService;
@Autowired
private PerformRulesService rulesService;
/**
* 绩效外部新增
*
* @param req
* @return
*/
@PostMapping("save")
@ApiUserAuth
public String receive(HttpServletRequest request, @RequestBody PerformSaveReq req) {
ApiResp<String> rsp = new ApiResp<>();
rsp.setMsg(ApiRespCodeEnum.SUCCESS.getLabel());
rsp.setCode(ApiRespCodeEnum.SUCCESS.getValue());
StringBuilder message = new StringBuilder();
message.append(String.format("【外部请求】类型【%s】 内容:%s", PerformTypeEnum.getByValue(req.getPerformType()).getDesc(), JSONObject.toJSONString(req)));
recordSysLog(request, message.toString());
try {
switch (PerformTypeEnum.getByValue(req.getPerformType())) {
case 考勤绩效:
attend(req);
break;
case 评价差评绩效:
review(req);
break;
case 评价投诉绩效:
complain(req);
break;
case 办件绩效:
gowork(req);
break;
case 效能绩效:
effect(req);
break;
case 其它绩效:
other(req);
break;
}
} catch (AppException e) {
log.error("接收数据失败", e);
rsp.setCode(e.getCode());
rsp.setMsg(e.getMessage());
return JSON.toJSONString(rsp);
} catch (Exception e) {
log.error("接收数据失败", e);
rsp.setCode(ApiRespCodeEnum.FAILED.getValue());
rsp.setMsg(e.getMessage());
return JSON.toJSONString(rsp);
}
log.info("响应【设备接收】【响应体】--> " + JSONObject.toJSONString(rsp));
return JSON.toJSONString(rsp);
}
private void attend(PerformSaveReq req) throws AppException {
//考勤保存
}
private void review(PerformSaveReq req) throws AppException {
//评价保存
}
private void complain(PerformSaveReq req) throws AppException {
//投诉保存
}
private void gowork(PerformSaveReq req) throws AppException {
//办件保存
}
private void effect(PerformSaveReq req) throws AppException {
//效能保存
}
private void other(PerformSaveReq req) throws AppException {
//其它保存
}
public static void main(String[] args) {
}
}
...@@ -55,19 +55,6 @@ import static com.mortals.xhx.common.key.ErrorCode.ERROR_TOKEN_EXPIRED_CONTENT; ...@@ -55,19 +55,6 @@ import static com.mortals.xhx.common.key.ErrorCode.ERROR_TOKEN_EXPIRED_CONTENT;
@RequestMapping("/api/v1/appeal") @RequestMapping("/api/v1/appeal")
public class AppealApiController extends AbstractBaseController<PerformReq> { public class AppealApiController extends AbstractBaseController<PerformReq> {
// @Autowired
// private CheckAttendRecordService checkAttendRecordService;
// @Autowired
// private CheckReviewRecordService checkReviewRecordService;
// @Autowired
// private CheckComplainRecordService checkComplainRecordService;
// @Autowired
// private CheckEffectRecordService checkEffectRecordService;
// @Autowired
// private CheckGoworkRecordService checkGoworkRecordService;
// @Autowired
// private CheckOtherRecordService checkOtherRecordService;
@Autowired @Autowired
private PerformAttendAppealService attendAppealService; private PerformAttendAppealService attendAppealService;
......
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 核查结果(1.加分或扣分,2.不扣分)枚举类
*
* @author zxfei
*/
public enum CheckResultEnum {
加分或扣分("加分或扣分", "加分或扣分"),
不扣分("不扣分", "不扣分");
private String value;
private String desc;
CheckResultEnum(String value, String desc) {
this.value = value;
this.desc = desc;
}
public String getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static CheckResultEnum getByValue(String value) {
for (CheckResultEnum checkResultEnum : CheckResultEnum.values()) {
if (checkResultEnum.getValue() == value) {
return checkResultEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(String... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (CheckResultEnum item : CheckResultEnum.values()) {
try {
boolean hasE = false;
for (String e : eItem) {
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
public enum PerformRulesTypeEnum {
考勤绩效(1, "attend"),
评价差评绩效(2, "review"),
评价投诉绩效(3, "complain"),
办件绩效(4, "gowork"),
效能绩效(5, "effect"),
其它绩效(1, "other");
private Integer value;
private String desc;
PerformRulesTypeEnum(Integer value, String desc) {
this.value = value;
this.desc = desc;
}
public Integer getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static PerformRulesTypeEnum getByValue(Integer value) {
for (PerformRulesTypeEnum partAttendanceEnum : PerformRulesTypeEnum.values()) {
if (partAttendanceEnum.getValue() == value) {
return partAttendanceEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(Integer... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (PerformRulesTypeEnum item : PerformRulesTypeEnum.values()) {
try {
boolean hasE = false;
for (Integer e : eItem) {
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
package com.mortals.xhx.module.perform.service; package com.mortals.xhx.module.perform.service;
import com.mortals.framework.service.ICRUDCacheService;
import com.mortals.framework.service.ICRUDService; import com.mortals.framework.service.ICRUDService;
import com.mortals.xhx.module.perform.model.PerformRulesEntity; import com.mortals.xhx.module.perform.model.PerformRulesEntity;
import com.mortals.xhx.module.perform.dao.PerformRulesDao; import com.mortals.xhx.module.perform.dao.PerformRulesDao;
...@@ -10,7 +11,7 @@ import com.mortals.xhx.module.perform.dao.PerformRulesDao; ...@@ -10,7 +11,7 @@ import com.mortals.xhx.module.perform.dao.PerformRulesDao;
* @author zxfei * @author zxfei
* @date 2023-05-16 * @date 2023-05-16
*/ */
public interface PerformRulesService extends ICRUDService<PerformRulesEntity,Long>{ public interface PerformRulesService extends ICRUDCacheService<PerformRulesEntity,Long> {
PerformRulesDao getDao(); PerformRulesDao getDao();
} }
\ No newline at end of file
package com.mortals.xhx.module.perform.service.impl; package com.mortals.xhx.module.perform.service.impl;
import cn.hutool.core.util.CharUtil;
import cn.hutool.core.util.ReUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.pinyin.PinyinUtil;
import com.mortals.framework.service.impl.AbstractCRUDCacheServiceImpl;
import com.mortals.xhx.common.code.PerformRulesTypeEnum;
import com.mortals.xhx.common.code.PerformTypeEnum;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.exception.AppException; import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context; import com.mortals.framework.model.Context;
import com.mortals.xhx.module.perform.dao.PerformRulesDao; import com.mortals.xhx.module.perform.dao.PerformRulesDao;
import com.mortals.xhx.module.perform.model.PerformRulesEntity; import com.mortals.xhx.module.perform.model.PerformRulesEntity;
import com.mortals.xhx.module.perform.service.PerformRulesService; import com.mortals.xhx.module.perform.service.PerformRulesService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils;
/** /**
* PerformRulesService * PerformRulesService
* 绩效规则信息 service实现 * 绩效规则信息 service实现
* *
* @author zxfei * @author zxfei
* @date 2023-05-16 * @date 2023-05-16
*/ */
@Service("performRulesService") @Service("performRulesService")
@Slf4j @Slf4j
public class PerformRulesServiceImpl extends AbstractCRUDServiceImpl<PerformRulesDao, PerformRulesEntity, Long> implements PerformRulesService { public class PerformRulesServiceImpl extends AbstractCRUDCacheServiceImpl<PerformRulesDao, PerformRulesEntity, Long> implements PerformRulesService {
@Override
protected String getExtKey(PerformRulesEntity data) {
return data.getRuleCode();
}
@Override
protected void saveBefore(PerformRulesEntity entity, Context context) throws AppException {
if (ObjectUtils.isEmpty(entity.getRuleCode())) {
//自定义默认规则code
String ruleCode = PerformRulesTypeEnum.getByValue(entity.getType()).getDesc() + "_" + PinyinUtil.getFirstLetter(ReUtil.replaceAll(entity.getName(), "[^\\u4E00-\\u9FA5]", ""), "");
entity.setRuleCode(ruleCode);
}
super.saveBefore(entity, context);
}
public static void main(String[] args) {
String str = "评价器评议、短信、电话回访等结果经核实为“不满意”的/次";
str = ReUtil.replaceAll(str, "[^\\u4E00-\\u9FA5]", "");
System.out.println(PinyinUtil.getPinyin(str));
System.out.println(PinyinUtil.getPinyin(str, ""));
System.out.println(PinyinUtil.getFirstLetter(str, ""));
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment