Browse Source

升级2.0.0

master
陈裕财 2 years ago
parent
commit
e4a192d3e7
  1. 32
      mdp-form/src/main/java/com/mdp/form/ctrl/FormDataController.java
  2. 78
      mdp-form/src/main/java/com/mdp/form/service/FormDataService.java
  3. 4
      mdp-form/src/main/java/com/mdp/form/service/FormDefService.java

32
mdp-form/src/main/java/com/mdp/form/ctrl/FormDataController.java

@ -148,8 +148,8 @@ public class FormDataController {
}) })
@RequestMapping(value="/add",method=RequestMethod.POST) @RequestMapping(value="/add",method=RequestMethod.POST)
public Result addFormData(@RequestBody FormData formData) { public Result addFormData(@RequestBody FormData formData) {
if(StringUtils.isEmpty(formData.getFlowState())) {
formData.setFlowState("0");
if(StringUtils.isEmpty(formData.getFstate())) {
formData.setFstate("0");
} }
FormDefVo formDefVo=formFieldService.getFormFieldFromCache(formData.getFormId()); FormDefVo formDefVo=formFieldService.getFormFieldFromCache(formData.getFormId());
@ -165,8 +165,8 @@ public class FormDataController {
formData.setCusername(user.getUsername()); formData.setCusername(user.getUsername());
formData.setDeptid(user.getDeptid()); formData.setDeptid(user.getDeptid());
formData.setDeptName(user.getDeptName()); formData.setDeptName(user.getDeptName());
formData.setCreateTime(new Date());
formData.setLastTime(new Date());
formData.setCtime(new Date());
formData.setLtime(new Date());
@ -175,9 +175,9 @@ public class FormDataController {
*/ */
Map<String,Object> formDataMap=BaseUtils.toMap(formData); Map<String,Object> formDataMap=BaseUtils.toMap(formData);
for (FormField field : formFields) { for (FormField field : formFields) {
Object pkValue= formDataMap.get(field.getFieldIdCamel());
if("1".equals(field.getIsRequired()) && ObjectTools.isEmpty(pkValue)){
return Result.error("field-required","%s不能为空",field.getFieldTitle());
Object pkValue= formDataMap.get(field.getIdCamel());
if("1".equals(field.getReq()) && ObjectTools.isEmpty(pkValue)){
return Result.error("field-required","%s不能为空",field.getTitle());
} }
} }
String bizKey=formDataService.createBizKey(formFields,formData); String bizKey=formDataService.createBizKey(formFields,formData);
@ -215,16 +215,16 @@ public class FormDataController {
if(formDataDb==null){ if(formDataDb==null){
return Result.error("data-0","数据已不存在"); return Result.error("data-0","数据已不存在");
} }
formData.setLastTime(new Date());
if(formData.getCreateTime()==null) {
formData.setCreateTime(new Date());
formData.setLtime(new Date());
if(formData.getCtime()==null) {
formData.setCtime(new Date());
} }
User user=LoginUtils.getCurrentUserInfo(); User user=LoginUtils.getCurrentUserInfo();
formData.setUserid(user.getUserid()); formData.setUserid(user.getUserid());
formData.setLastTime(new Date());
formData.setLtime(new Date());
if(StringUtils.isEmpty(formData.getFlowState())) {
formData.setFlowState("0");
if(StringUtils.isEmpty(formData.getFstate())) {
formData.setFstate("0");
} }
FormDefVo formDefVo=formFieldService.getFormFieldFromCache(formData.getFormId()); FormDefVo formDefVo=formFieldService.getFormFieldFromCache(formData.getFormId());
@ -237,9 +237,9 @@ public class FormDataController {
*/ */
Map<String,Object> formDataMap=BaseUtils.toMap(formData); Map<String,Object> formDataMap=BaseUtils.toMap(formData);
for (FormField field : formFields) { for (FormField field : formFields) {
Object pkValue= formDataMap.get(field.getFieldIdCamel());
if("1".equals(field.getIsRequired()) && ObjectTools.isEmpty(pkValue)){
return Result.error("field-required","%s不能为空",field.getFieldTitle());
Object pkValue= formDataMap.get(field.getIdCamel());
if("1".equals(field.getReq()) && ObjectTools.isEmpty(pkValue)){
return Result.error("field-required","%s不能为空",field.getTitle());
} }
} }

78
mdp-form/src/main/java/com/mdp/form/service/FormDataService.java

@ -77,13 +77,13 @@ public class FormDataService extends BaseService<FormDataMapper,FormData> {
public String createBizKey(List<FormField> formFields,FormData formData){ public String createBizKey(List<FormField> formFields,FormData formData){
List<String> pks=new ArrayList<>(); List<String> pks=new ArrayList<>();
List<FormField> pkFields=formFields.stream().filter(k->k.getIsBizKey().endsWith("1")).collect(Collectors.toList());
List<FormField> pkFields=formFields.stream().filter(k->k.getBkey().endsWith("1")).collect(Collectors.toList());
if(pkFields==null || pkFields.size()==0){//没有业务主键则取id if(pkFields==null || pkFields.size()==0){//没有业务主键则取id
return ""; return "";
} }
Map<String,Object> formDataMap= BaseUtils.toMap(formData); Map<String,Object> formDataMap= BaseUtils.toMap(formData);
FormField pk=pkFields.get(0); FormField pk=pkFields.get(0);
String isBizKey=pk.getIsBizKey();
String isBizKey=pk.getBkey();
if(isBizKey.startsWith("1")){ if(isBizKey.startsWith("1")){
pks.add(formData.getCuserid()); pks.add(formData.getCuserid());
} }
@ -91,11 +91,11 @@ public class FormDataService extends BaseService<FormDataMapper,FormData> {
pks.add(formData.getDeptid()); pks.add(formData.getDeptid());
} }
for (FormField pkField : pkFields) { for (FormField pkField : pkFields) {
Object pkValue= formDataMap.get(pkField.getFieldIdCamel());
Object pkValue= formDataMap.get(pkField.getIdCamel());
if(ObjectTools.isEmpty(pkValue)){ if(ObjectTools.isEmpty(pkValue)){
throw new BizException(LangTips.errMsg("pk-field-required","%s不能为空",pkField.getFieldTitle()));
throw new BizException(LangTips.errMsg("pk-field-required","%s不能为空",pkField.getTitle()));
} }
pks.add((String) formDataMap.get(pkField.getFieldIdCamel()));
pks.add((String) formDataMap.get(pkField.getIdCamel()));
} }
return pks.stream().collect(Collectors.joining(",")); return pks.stream().collect(Collectors.joining(","));
} }
@ -106,7 +106,7 @@ public class FormDataService extends BaseService<FormDataMapper,FormData> {
* @param formId * @param formId
* @param procInstId * @param procInstId
*/ */
public void updateFlowStateByProcInst(String flowState,String formId,String procInstId) {
public void updateFstateByProcInst(String flowState,String formId,String procInstId) {
Map<String,Object> p=new HashMap<>(); Map<String,Object> p=new HashMap<>();
p.put("flowState", flowState); p.put("flowState", flowState);
p.put("formId", formId); p.put("formId", formId);
@ -119,15 +119,15 @@ public class FormDataService extends BaseService<FormDataMapper,FormData> {
* @param formData * @param formData
* @return * @return
*/ */
public int insertOrUpdate(FormDataVo formData, boolean checkFlowState) {
public int insertOrUpdate(FormDataVo formData, boolean checkFstate) {
String formId=formData.getFormId(); String formId=formData.getFormId();
FormDefVo formDefVo=formFieldService.getFormFieldFromCache(formId); FormDefVo formDefVo=formFieldService.getFormFieldFromCache(formId);
String bizKey=this.createBizKey(formDefVo.getFormFields(), formData); String bizKey=this.createBizKey(formDefVo.getFormFields(), formData);
formData.setBizKey(bizKey); formData.setBizKey(bizKey);
if(StringUtils.isEmpty(formData.getId())){ if(StringUtils.isEmpty(formData.getId())){
formData.setId(this.createKey("id")); formData.setId(this.createKey("id"));
formData.setCreateTime(new Date());
formData.setLastTime(new Date());
formData.setCtime(new Date());
formData.setLtime(new Date());
FormData fd=this.getDbFormDataByBizKey(formId,formData.getBizKey()); FormData fd=this.getDbFormDataByBizKey(formId,formData.getBizKey());
if(fd!=null) { if(fd!=null) {
throw new BizException("exists-form-data-biz-key","bizKey","数据已经存在不能再添加"); throw new BizException("exists-form-data-biz-key","bizKey","数据已经存在不能再添加");
@ -135,20 +135,20 @@ public class FormDataService extends BaseService<FormDataMapper,FormData> {
return this.insert(formData); return this.insert(formData);
} }
}else{ }else{
formData.setLastTime(new Date());
formData.setLtime(new Date());
FormData fd=this.getDbFormDataByBizKey(formId,formData.getBizKey()); FormData fd=this.getDbFormDataByBizKey(formId,formData.getBizKey());
if(fd==null) {//如果通过bizKey查不出来 if(fd==null) {//如果通过bizKey查不出来
FormData fdObject=getById(formData.getId()); FormData fdObject=getById(formData.getId());
if(fdObject!=null) {//通过id可以查出来通过bizKey查不出来说明是修改了bizKey,可以更新 if(fdObject!=null) {//通过id可以查出来通过bizKey查不出来说明是修改了bizKey,可以更新
if(checkFlowState) {
if("0".equals(fdObject.getFlowState())) {
formData.setLastTime(new Date());
if(checkFstate) {
if("0".equals(fdObject.getFstate())) {
formData.setLtime(new Date());
return super.updateByPk(formData); return super.updateByPk(formData);
}else { }else {
if("1".equals(fdObject.getFlowState())) {
if("1".equals(fdObject.getFstate())) {
throw new BizException("flow-state-error-001","审核中的数据不允许修改"); throw new BizException("flow-state-error-001","审核中的数据不允许修改");
}else if("2".equals(fdObject.getFlowState())) {
}else if("2".equals(fdObject.getFstate())) {
throw new BizException("flow-state-error-002","审核完毕的数据不允许修改"); throw new BizException("flow-state-error-002","审核完毕的数据不允许修改");
}else { }else {
throw new BizException("flow-state-error-003","数据状态不正确"); throw new BizException("flow-state-error-003","数据状态不正确");
@ -156,14 +156,14 @@ public class FormDataService extends BaseService<FormDataMapper,FormData> {
} }
}else { }else {
formData.setLastTime(new Date());
formData.setLtime(new Date());
return super.updateByPk(formData); return super.updateByPk(formData);
} }
}else {//通过id也查不出来通过bizKey查不出来说明是新增 }else {//通过id也查不出来通过bizKey查不出来说明是新增
formData.setCreateTime(new Date());
formData.setLastTime(new Date());
if(StringUtils.isEmpty(formData.getFlowState())) {
formData.setFlowState("0");
formData.setCtime(new Date());
formData.setLtime(new Date());
if(StringUtils.isEmpty(formData.getFstate())) {
formData.setFstate("0");
} }
return this.insert(formData); return this.insert(formData);
} }
@ -172,21 +172,21 @@ public class FormDataService extends BaseService<FormDataMapper,FormData> {
//如果id相同说明是同一条数据 //如果id相同说明是同一条数据
if(fd.getId().equals(formData.getId())) { if(fd.getId().equals(formData.getId())) {
if(checkFlowState) {
if("0".equals(fd.getFlowState())) {
formData.setLastTime(new Date());
if(checkFstate) {
if("0".equals(fd.getFstate())) {
formData.setLtime(new Date());
return super.updateByPk(formData); return super.updateByPk(formData);
}else { }else {
if("1".equals(fd.getFlowState())) {
if("1".equals(fd.getFstate())) {
throw new BizException("flow-state-error-001","审核中的数据不允许修改"); throw new BizException("flow-state-error-001","审核中的数据不允许修改");
}else if("2".equals(fd.getFlowState())) {
}else if("2".equals(fd.getFstate())) {
throw new BizException("flow-state-error-002","审核完毕的数据不允许修改"); throw new BizException("flow-state-error-002","审核完毕的数据不允许修改");
}else { }else {
throw new BizException("flow-state-error-003","数据状态不正确"); throw new BizException("flow-state-error-003","数据状态不正确");
} }
} }
}else { }else {
formData.setLastTime(new Date());
formData.setLtime(new Date());
return super.updateByPk(formData); return super.updateByPk(formData);
} }
}else {//如果id不相同说明不是同一条数据 }else {//如果id不相同说明不是同一条数据
@ -202,7 +202,7 @@ public class FormDataService extends BaseService<FormDataMapper,FormData> {
* 不检查数据状态 * 不检查数据状态
* @param formDatas * @param formDatas
*/ */
public void batchInsertOrUpdate(List<FormDataVo> formDatas,boolean updateFlowState) {
public void batchInsertOrUpdate(List<FormDataVo> formDatas,boolean updateFstate) {
String formId=formDatas.get(0).getFormId(); String formId=formDatas.get(0).getFormId();
FormDefVo fromDefVo=this.formFieldService.getFormFieldFromCache(formId); FormDefVo fromDefVo=this.formFieldService.getFormFieldFromCache(formId);
@ -221,12 +221,12 @@ public class FormDataService extends BaseService<FormDataMapper,FormData> {
if(fd==null) {//如果通过bizKey查不出来 if(fd==null) {//如果通过bizKey查不出来
FormData fdObject=this.getById(formData.getId()); FormData fdObject=this.getById(formData.getId());
if(fdObject!=null) {//通过id可以查出来通过bizKey查不出来说明是修改了bizKey,可以更新 if(fdObject!=null) {//通过id可以查出来通过bizKey查不出来说明是修改了bizKey,可以更新
formData.setLastTime(new Date());
formData.setLtime(new Date());
needUpdateList.add(formData); needUpdateList.add(formData);
}else {//通过id也查不出来通过bizKey查不出来说明是新增 }else {//通过id也查不出来通过bizKey查不出来说明是新增
formData.setCreateTime(new Date());
formData.setLastTime(new Date());
formData.setFlowState("1");
formData.setCtime(new Date());
formData.setLtime(new Date());
formData.setFstate("1");
needInsertList.add(formData); needInsertList.add(formData);
} }
@ -234,7 +234,7 @@ public class FormDataService extends BaseService<FormDataMapper,FormData> {
//如果id相同说明是同一条数据 //如果id相同说明是同一条数据
if(fd.getId().equals(formData.getId())) { if(fd.getId().equals(formData.getId())) {
formData.setLastTime(new Date());
formData.setLtime(new Date());
needUpdateList.add(formData); needUpdateList.add(formData);
}else {//如果id不相同说明不是同一条数据 }else {//如果id不相同说明不是同一条数据
throw new BizException("form-data-biz-key-exists","数据已经存在,不能继续添加,请检查是否关键数据错误"); throw new BizException("form-data-biz-key-exists","数据已经存在,不能继续添加,请检查是否关键数据错误");
@ -248,11 +248,11 @@ public class FormDataService extends BaseService<FormDataMapper,FormData> {
} }
if(needUpdateList.size()>0) { if(needUpdateList.size()>0) {
if(updateFlowState) {
if(updateFstate) {
this.updateBatchById(formDatas.stream().map(k->(FormData)k).collect(Collectors.toList())); this.updateBatchById(formDatas.stream().map(k->(FormData)k).collect(Collectors.toList()));
}else { }else {
this.updateBatchById(formDatas.stream().map(k->{ this.updateBatchById(formDatas.stream().map(k->{
k.setFlowState(null);
k.setFstate(null);
return (FormData)k; return (FormData)k;
}).collect(Collectors.toList())); }).collect(Collectors.toList()));
@ -303,7 +303,7 @@ public class FormDataService extends BaseService<FormDataMapper,FormData> {
for (String fieldId : fieldIds.split(",")) { for (String fieldId : fieldIds.split(",")) {
Object value=formDatasMap.get(fieldId); Object value=formDatasMap.get(fieldId);
needUpdateFormDataMap.put(fieldId, value); needUpdateFormDataMap.put(fieldId, value);
if(formDefVo.getFormFields().stream().filter(k->k.getFieldIdCamel().equals(fieldId)).findAny().isPresent()){
if(formDefVo.getFormFields().stream().filter(k->k.getIdCamel().equals(fieldId)).findAny().isPresent()){
needUpdateBizKey=true; needUpdateBizKey=true;
} }
} }
@ -331,7 +331,7 @@ public class FormDataService extends BaseService<FormDataMapper,FormData> {
if(StringUtils.isEmpty(formDataVo.getId())) { if(StringUtils.isEmpty(formDataVo.getId())) {
formDataVo.setId(this.createKey("id")); formDataVo.setId(this.createKey("id"));
} }
formDataVo.setFlowState("1");
formDataVo.setFstate("1");
formDatas.add(formDataVo); formDatas.add(formDataVo);
FormDataProcessApprova approva=BaseUtils.fromMap(flowVars, FormDataProcessApprova.class); FormDataProcessApprova approva=BaseUtils.fromMap(flowVars, FormDataProcessApprova.class);
@ -347,13 +347,13 @@ public class FormDataService extends BaseService<FormDataMapper,FormData> {
} }
}else if("PROCESS_COMPLETED".equals(eventName)) { }else if("PROCESS_COMPLETED".equals(eventName)) {
if("1".equals(agree)) { if("1".equals(agree)) {
this.updateFlowStateByProcInst("2", formId, procInstId);
this.updateFstateByProcInst("2", formId, procInstId);
}else { }else {
this.updateFlowStateByProcInst("3", formId, procInstId);
this.updateFstateByProcInst("3", formId, procInstId);
} }
}else if("PROCESS_CANCELLED".equals(eventName)) { }else if("PROCESS_CANCELLED".equals(eventName)) {
this.updateFlowStateByProcInst("4", formId, procInstId);
this.updateFstateByProcInst("4", formId, procInstId);
} }
} }
} }

4
mdp-form/src/main/java/com/mdp/form/service/FormDefService.java

@ -102,7 +102,7 @@ public class FormDefService extends BaseService<FormDefMapper,FormDef> {
List<FormField> formFields=formDefVo.getFormFields(); List<FormField> formFields=formDefVo.getFormFields();
for (FormField formField : formFields) { for (FormField formField : formFields) {
String fieldBizKey=formField.getIsBizKey();
String fieldBizKey=formField.getBkey();
if(StringUtils.isEmpty(fieldBizKey) ) { if(StringUtils.isEmpty(fieldBizKey) ) {
throw new BizException("is-biz-key-err-001", "isBizKey", "表单字段定义的主键编码错误,长度应为3位 格式位 111 第一位代表创建人是否为主键,第二位代表创建部门是否为主键,第三位代表该字段是否为主键"); throw new BizException("is-biz-key-err-001", "isBizKey", "表单字段定义的主键编码错误,长度应为3位 格式位 111 第一位代表创建人是否为主键,第二位代表创建部门是否为主键,第三位代表该字段是否为主键");
}else if( fieldBizKey.length()!=3) { }else if( fieldBizKey.length()!=3) {
@ -131,7 +131,7 @@ public class FormDefService extends BaseService<FormDefMapper,FormDef> {
formDef.setDeptid(user.getDeptid()); formDef.setDeptid(user.getDeptid());
formDef.setDeptName(user.getDeptName()); formDef.setDeptName(user.getDeptName());
for (FormField formField : formFields) { for (FormField formField : formFields) {
String fieldBizKey=formField.getIsBizKey();
String fieldBizKey=formField.getBkey();
if(StringUtils.isEmpty(fieldBizKey) ) { if(StringUtils.isEmpty(fieldBizKey) ) {
throw new BizException("is-biz-key-err-001", "isBizKey", "表单字段定义的主键编码错误,长度应为3位 格式位 111 第一位代表创建人是否为主键,第二位代表创建部门是否为主键,第三位代表该字段是否为主键"); throw new BizException("is-biz-key-err-001", "isBizKey", "表单字段定义的主键编码错误,长度应为3位 格式位 111 第一位代表创建人是否为主键,第二位代表创建部门是否为主键,第三位代表该字段是否为主键");
}else if( fieldBizKey.length()!=3) { }else if( fieldBizKey.length()!=3) {

Loading…
Cancel
Save