4 changed files with 105 additions and 0 deletions
-
42src/main/java/com/xujie/sys/common/utils/FillRuleUtil.java
-
47src/main/java/com/xujie/sys/modules/ruler/CodeRule.java
-
9src/main/java/com/xujie/sys/modules/ruler/Consts.java
-
7src/main/java/com/xujie/sys/modules/ruler/IFillRuleHandler.java
@ -0,0 +1,42 @@ |
|||
package com.xujie.sys.common.utils; |
|||
|
|||
import com.alibaba.fastjson.JSON; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|||
import com.xujie.sys.modules.ruler.IFillRuleHandler; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
|
|||
@Slf4j |
|||
public class FillRuleUtil { |
|||
public static Object fillRule(String ruleCode, JSONObject formData) { |
|||
if (!StringUtils.isEmpty(ruleCode)) { |
|||
try { |
|||
|
|||
ServiceImpl impl = (ServiceImpl) SpringContextUtils.getBean("SysFillRuleServiceImpl"); |
|||
QueryWrapper queryWrapper = new QueryWrapper(); |
|||
queryWrapper.eq("rule_code", ruleCode); |
|||
JSONObject entity = JSON.parseObject(JSON.toJSONString(impl.getOne(queryWrapper))); |
|||
if (entity == null) { |
|||
log.warn("填值规则:" + ruleCode + " 不存在"); |
|||
return null; |
|||
} |
|||
String ruleClass = entity.getString("ruleClass"); |
|||
JSONObject params = entity.getJSONObject("ruleParams"); |
|||
if (params == null) { |
|||
params = new JSONObject(); |
|||
} |
|||
if (formData == null) { |
|||
formData = new JSONObject(); |
|||
} |
|||
// 通过反射执行配置的类里的方法 |
|||
IFillRuleHandler ruleHandler = (IFillRuleHandler) Class.forName(ruleClass).newInstance(); |
|||
return ruleHandler.execute(params, formData); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
} |
|||
@ -0,0 +1,47 @@ |
|||
package com.xujie.sys.modules.ruler; |
|||
|
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
import com.xujie.sys.common.utils.SpringContextUtils; |
|||
import com.xujie.sys.modules.sys.dao.SysCodeCountMapper; |
|||
import com.xujie.sys.modules.sys.entity.SysCodeCount; |
|||
import com.xujie.sys.modules.sys.service.impl.SysCodeCountServiceImpl; |
|||
import org.springframework.util.CollectionUtils; |
|||
|
|||
import java.text.SimpleDateFormat; |
|||
import java.util.Date; |
|||
import java.util.List; |
|||
|
|||
public class CodeRule implements IFillRuleHandler{ |
|||
@Override |
|||
public Object execute(JSONObject params, JSONObject formData) { |
|||
String codeno=formData.get("codeno").toString(); |
|||
SysCodeCountServiceImpl sysCodeCountImpl = (SysCodeCountServiceImpl)SpringContextUtils.getBean("SysCodeCountServiceImpl"); |
|||
SimpleDateFormat format = new SimpleDateFormat("yyMMdd") ; |
|||
String updateDate=format.format(new Date()) ; |
|||
QueryWrapper<SysCodeCount> queryWrapper=new QueryWrapper<>() ; |
|||
queryWrapper.eq("code_no",codeno); |
|||
List<SysCodeCount> firs= sysCodeCountImpl.list(queryWrapper); |
|||
|
|||
SysCodeCount fir = null; |
|||
int cnum=0; |
|||
if(CollectionUtils.isEmpty(firs)){ |
|||
cnum++; |
|||
fir=new SysCodeCount(); |
|||
fir.setCnum(cnum); |
|||
fir.setCodeNo(codeno); |
|||
fir.setUpdateDate(new Date()); |
|||
fir.setCreateDate(new Date()); |
|||
sysCodeCountImpl.save(fir); |
|||
}else{ |
|||
fir = firs.get(0); |
|||
cnum= fir.getCnum(); |
|||
cnum++; |
|||
fir.setCnum(cnum); |
|||
fir.setUpdateDate(new Date()); |
|||
sysCodeCountImpl.updateById(fir); |
|||
} |
|||
String value = codeno + updateDate + String.format("%04d", cnum) ; |
|||
return value; |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
package com.xujie.sys.modules.ruler; |
|||
|
|||
public interface Consts { |
|||
public final static String PROJECT = "PJ"; |
|||
|
|||
public final static String PROJECTINCOME = "YS"; |
|||
public final static String PROJECTPLAN = "P"; |
|||
public final static String PROJECTTASK = "Q"; |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
package com.xujie.sys.modules.ruler; |
|||
|
|||
import com.alibaba.fastjson.JSONObject; |
|||
|
|||
public interface IFillRuleHandler { |
|||
Object execute(JSONObject params, JSONObject formData); |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue