| | |
| | | import com.vci.ubcs.starter.exception.VciBaseException; |
| | | import com.vci.ubcs.starter.revision.model.BaseModel; |
| | | import com.vci.ubcs.starter.web.util.VciBaseUtil; |
| | | import org.apache.poi.ss.formula.functions.T; |
| | | import org.springblade.core.secure.BladeUser; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.utils.Func; |
| | | |
| | | import java.lang.reflect.Field; |
| | | import java.math.BigDecimal; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Locale; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 新增时默认值属性赋值 |
| | |
| | | * @return |
| | | * @throws VciBaseException |
| | | */ |
| | | public static <T extends BaseModel> T addDefaultAttrAssimt(T object,String btmName) throws VciBaseException { |
| | | public static <T extends BaseModel> T addDefaultAttrAssimt(T object, String btmName) throws VciBaseException { |
| | | BaseModel baseModel = object; |
| | | try { |
| | | baseModel.setOid(VciBaseUtil.getPk()); |
| | |
| | | baseModel.setLastModifyTime(new Date()); |
| | | baseModel.setTs(new Date()); |
| | | baseModel.setRevisionOid(VciBaseUtil.getPk()); |
| | | // 用户id |
| | | // String userId = AuthUtil.getUserId().toString(); |
| | | baseModel.setBtmname(btmName); |
| | | baseModel.setCreator(AuthUtil.getUser().getAccount()); |
| | | baseModel.setFirstR("1"); |
| | |
| | | // 设置所有者 |
| | | baseModel.setOwner(AuthUtil.getUserId().toString()); |
| | | } |
| | | |
| | | baseModel.setVersionSeq(1); |
| | | baseModel.setVersionRule("0"); |
| | | baseModel.setVersionValue("1"); |
| | |
| | | baseModel.setRevisionValue("1"); |
| | | baseModel.setRevisionRule("1"); |
| | | baseModel.setTenantId(AuthUtil.getTenantId()); |
| | | }catch (VciBaseException e){ |
| | | e.printStackTrace(); |
| | | } |
| | | return (T)baseModel; |
| | | } |
| | | |
| | | /** |
| | | * 当在多线程流中调用时,获取不到请求头信息, |
| | | * 所以得在多线程流外面获取到request |
| | | * @param object 继承了BaseModel的实体对象 |
| | | * @param <T> 返回值的类型 |
| | | * @param btmName 业务类型 |
| | | * @return |
| | | * @throws VciBaseException |
| | | */ |
| | | public static <T extends BaseModel> T addDefaultAttrAssimt(T object, String btmName, BladeUser user) throws VciBaseException { |
| | | BaseModel baseModel = object; |
| | | try { |
| | | baseModel.setOid(VciBaseUtil.getPk()); |
| | | baseModel.setCreateTime(new Date()); |
| | | baseModel.setNameOid(VciBaseUtil.getPk()); |
| | | baseModel.setLastModifyTime(new Date()); |
| | | baseModel.setTs(new Date()); |
| | | baseModel.setRevisionOid(VciBaseUtil.getPk()); |
| | | baseModel.setBtmname(btmName); |
| | | String account = Func.isNotEmpty(user) ? user.getAccount():AuthUtil.getUser().getAccount(); |
| | | baseModel.setCreator(account); |
| | | baseModel.setFirstR("1"); |
| | | baseModel.setFirstV("1"); |
| | | baseModel.setLastR("1"); |
| | | baseModel.setLastV("1"); |
| | | // TODO:目前只有编码规则中有用到,后期需要去掉这段代码的话,就把他加在编码规则新增中去 |
| | | if(Func.isBlank(baseModel.getOwner())){ |
| | | // 设置所有者 |
| | | baseModel.setOwner(Func.isNotEmpty(user) ? user.getUserId().toString():AuthUtil.getUserId().toString()); |
| | | } |
| | | baseModel.setVersionSeq(1); |
| | | baseModel.setVersionValue("1"); |
| | | baseModel.setVersionRule("0"); |
| | | baseModel.setRevisionSeq(1); |
| | | baseModel.setRevisionValue("1"); |
| | | baseModel.setRevisionRule("1"); |
| | | baseModel.setRevisionOid(VciBaseUtil.getPk()); |
| | | baseModel.setLastModifier(account); |
| | | baseModel.setTenantId(Func.isNotEmpty(user) ? user.getTenantId():AuthUtil.getTenantId()); |
| | | }catch (VciBaseException e){ |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | public static <T extends BaseModel> T updateDefaultAttrAssimt(T object) throws VciBaseException { |
| | | BaseModel baseModel = object; |
| | | try { |
| | | baseModel.setLastModifyTime(new Date()); |
| | | baseModel.setTs(new Date()); |
| | | Date date = new Date(); |
| | | baseModel.setLastModifyTime(date); |
| | | baseModel.setTs(date); |
| | | // 用户id |
| | | // String userId = AuthUtil.getUserId().toString(); |
| | | // 要求改成账号 |
| | | String account = AuthUtil.getUserAccount(); |
| | | baseModel.setLastModifier(account); |
| | | baseModel.setLastModifier(AuthUtil.getUser().getAccount()); |
| | | }catch (VciBaseException e){ |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 新增时填充默认值 |
| | | * 修改时填充默认值:多线程流中调用 |
| | | * @param object 继承了BaseModel的实体对象 |
| | | * @param <T> 返回值的类型 |
| | | * @return |
| | | * @throws VciBaseException |
| | | */ |
| | | public static <T extends BaseModel> T copplyDefaultAttrAssimt(Map<String,String> dataMap, T object,boolean isCase) throws VciBaseException { |
| | | public static <T extends BaseModel> T updateDefaultAttrAssimt(T object, BladeUser user) throws VciBaseException { |
| | | BaseModel baseModel = object; |
| | | try { |
| | | baseModel.setLastModifyTime(new Date()); |
| | | baseModel.setTs(new Date()); |
| | | // 用户id |
| | | // String userId = AuthUtil.getUserId().toString(); |
| | | // 要求改成账号 |
| | | baseModel.setLastModifier(Func.isNotEmpty(user) ? user.getAccount():AuthUtil.getUser().getAccount()); |
| | | }catch (VciBaseException e){ |
| | | e.printStackTrace(); |
| | | } |
| | | return (T)baseModel; |
| | | } |
| | | |
| | | /** |
| | | * 新增时填充默认值:多线程流中调用 |
| | | * @param object 继承了BaseModel的实体对象 |
| | | * @param <T> 返回值的类型 |
| | | * @return |
| | | * @throws VciBaseException |
| | | */ |
| | | public static <T extends BaseModel> T copplyDefaultAttrAssimt(Map<String,String> dataMap, T object,boolean isCase, BladeUser user) throws VciBaseException { |
| | | BaseModel baseModel = object; |
| | | baseModel.getData().putAll(dataMap); |
| | | try { |
| | |
| | | Object value=dataMap.get(key); |
| | | newDataMap.put(key.toLowerCase(Locale.ROOT),value); |
| | | }*/ |
| | | /* dataMap.forEach((key,value)->{ |
| | | /* dataMap.forEach((key,value)->{ |
| | | newDataMap.put(key.toLowerCase(Locale.ROOT),value); |
| | | });*/ |
| | | //baseModel.setData((Map)newDataMap); |
| | |
| | | |
| | | baseModel.setRevisionOid(dataMap.getOrDefault(isCase?"REVISIONOID":"revisionoid","")); |
| | | baseModel.setRevisionValue(dataMap.getOrDefault(isCase?"REVISIONVALUE":"revisionvalue","")); |
| | | baseModel.setLastModifier(AuthUtil.getUser().getAccount()); |
| | | baseModel.setLastModifier(Func.isNotEmpty(user) ? user.getAccount():AuthUtil.getUser().getAccount()); |
| | | baseModel.setLcStatus(dataMap.getOrDefault(isCase?"LCSTATUS":"lcstatus","")); |
| | | baseModel.setName(dataMap.getOrDefault(isCase?"NAME":"name","")); |
| | | baseModel.setTenantId(dataMap.getOrDefault(isCase?"TENANT_ID":"tenant_id","")); |
| | |
| | | } |
| | | }catch (VciBaseException e){ |
| | | e.printStackTrace(); |
| | | throw e; |
| | | } |
| | | return (T)baseModel; |
| | | } |
| | |
| | | } |
| | | return date; |
| | | } |
| | | |
| | | /** |
| | | * map对象转换为小写 |
| | | * @param dataMapList |
| | | * @param isLowerCase |
| | | */ |
| | | public static void mapToLowerCase(List<Map<String,String>> dataMapList, boolean isLowerCase){ |
| | | // 遍历List中的每个Map |
| | | for (Map<String, String> map : dataMapList) { |
| | | Map<String, String> newMap = new HashMap<>(); |
| | | // 遍历每个Map中的key,并将其转换为小写 |
| | | for (String key : map.keySet()) { |
| | | newMap.put(isLowerCase ? key.toLowerCase():key.toLowerCase(Locale.ROOT), map.get(key)); |
| | | } |
| | | // 用新的Map替换旧的Map |
| | | dataMapList.set(dataMapList.indexOf(map), newMap); |
| | | } |
| | | } |
| | | |
| | | } |