Commit 4cde68d2 authored by suhuiguang's avatar suhuiguang

1.修改更新报错metaHander

parent 6ee20e2f
package com.yeejoin.amos.boot.biz.config; package com.yeejoin.amos.boot.biz.config;
import java.util.Date;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.yeejoin.amos.boot.biz.common.annotation.FillCommonUserField; import com.yeejoin.amos.boot.biz.common.annotation.FillCommonUserField;
...@@ -17,6 +7,15 @@ import com.yeejoin.amos.boot.biz.common.bo.ReginParams; ...@@ -17,6 +7,15 @@ import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
import com.yeejoin.amos.boot.biz.common.utils.RedisKey; import com.yeejoin.amos.boot.biz.common.utils.RedisKey;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils; import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel; import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import java.util.Date;
import java.util.Map;
/** /**
* @author Dell * @author Dell
...@@ -43,18 +42,19 @@ public class MetaHandler implements MetaObjectHandler { ...@@ -43,18 +42,19 @@ public class MetaHandler implements MetaObjectHandler {
@Override @Override
public void insertFill(MetaObject metaObject) { public void insertFill(MetaObject metaObject) {
// autoFillUser(metaObject, metaObject.getOriginalObject()); // autoFillUser(metaObject, metaObject.getOriginalObject());
Date currentDate = new Date(); Date currentDate = new Date();
Class clazz = metaObject.getOriginalObject().getClass(); Class clazz = metaObject.getOriginalObject().getClass();
FillCommonUserField annotation = (FillCommonUserField) clazz.getAnnotation(FillCommonUserField.class); FillCommonUserField annotation = (FillCommonUserField) clazz.getAnnotation(FillCommonUserField.class);
if(annotation == null || annotation.isAutoFill()){ if (annotation == null || annotation.isAutoFill()) {
autoFillUser(metaObject,metaObject.getOriginalObject()); autoFillUser(metaObject, metaObject.getOriginalObject());
} }
//如果有上传创建时间,不需要修改 //如果有上传创建时间,不需要修改
if(metaObject.getValue("createDate")==null){ // if(metaObject.getValue("createDate")==null){
this.setFieldValByName("createDate", currentDate, metaObject); // this.setFieldValByName("createDate", currentDate, metaObject);
} // }
} }
private void autoFillUser(MetaObject metaObject, Object entity) { private void autoFillUser(MetaObject metaObject, Object entity) {
//获取用户信息 以及当前用户登录公司部门,角色 //获取用户信息 以及当前用户登录公司部门,角色
String userId = RequestContext.getExeUserId(); String userId = RequestContext.getExeUserId();
...@@ -84,27 +84,27 @@ public class MetaHandler implements MetaObjectHandler { ...@@ -84,27 +84,27 @@ public class MetaHandler implements MetaObjectHandler {
this.setFieldValByName("recDate", currentDate, metaObject); this.setFieldValByName("recDate", currentDate, metaObject);
} }
//以下为装备中转移过来的 //以下为装备中转移过来的
if (isExistField("userId", entity)) { if (isExistField("userId", entity)) {
this.setFieldValByName("userId", Long.valueOf(agencyUserModel.getUserId()), metaObject); this.setFieldValByName("userId", Long.valueOf(agencyUserModel.getUserId()), metaObject);
} }
if (isExistField("creatorId", entity)) { if (isExistField("creatorId", entity)) {
this.setFieldValByName("creatorId", Long.valueOf(agencyUserModel.getUserId()), metaObject); this.setFieldValByName("creatorId", Long.valueOf(agencyUserModel.getUserId()), metaObject);
} }
if (isExistField("userName", entity)) { if (isExistField("userName", entity)) {
this.setFieldValByName("userName", agencyUserModel.getRealName(), metaObject); this.setFieldValByName("userName", agencyUserModel.getRealName(), metaObject);
} }
if (isExistField("companyName", entity)) { if (isExistField("companyName", entity)) {
this.setFieldValByName("companyName", reginParams.getCompany().getCompanyName(), metaObject); this.setFieldValByName("companyName", reginParams.getCompany().getCompanyName(), metaObject);
} }
if (isExistField("orgCode", entity)) { if (isExistField("orgCode", entity)) {
this.setFieldValByName("orgCode", reginParams.getCompany().getOrgCode(), metaObject); this.setFieldValByName("orgCode", reginParams.getCompany().getOrgCode(), metaObject);
} }
if (isExistField("departmentName", entity)) { if (isExistField("departmentName", entity)) {
this.setFieldValByName("departmentName", ObjectUtils.isEmpty(reginParams.getDepartment())?"":reginParams.getDepartment().getDepartmentName(), metaObject); this.setFieldValByName("departmentName", ObjectUtils.isEmpty(reginParams.getDepartment()) ? "" : reginParams.getDepartment().getDepartmentName(), metaObject);
} }
if (isExistField("departmentOrgcode", entity)) { if (isExistField("departmentOrgcode", entity)) {
this.setFieldValByName("departmentOrgcode", ObjectUtils.isEmpty(reginParams.getDepartment())?"":reginParams.getDepartment().getOrgCode(), metaObject); this.setFieldValByName("departmentOrgcode", ObjectUtils.isEmpty(reginParams.getDepartment()) ? "" : reginParams.getDepartment().getOrgCode(), metaObject);
} }
// if (isExistField("updateTime", entity)) { // if (isExistField("updateTime", entity)) {
// Date currentDate = new Date(); // Date currentDate = new Date();
// this.setFieldValByName("updateTime", currentDate, metaObject); // this.setFieldValByName("updateTime", currentDate, metaObject);
...@@ -133,9 +133,17 @@ public class MetaHandler implements MetaObjectHandler { ...@@ -133,9 +133,17 @@ public class MetaHandler implements MetaObjectHandler {
*/ */
@Override @Override
public void updateFill(MetaObject metaObject) { public void updateFill(MetaObject metaObject) {
Object updateEntity = ((Map) metaObject.getOriginalObject()).get("et"); // DOTO tianbo 逻辑
autoFillUser(metaObject, updateEntity); Class clazz = metaObject.getOriginalObject().getClass();
FillCommonUserField annotation = (FillCommonUserField) clazz.getAnnotation(FillCommonUserField.class);
if (annotation == null || annotation.isAutoFill()) {
Object updateEntity = ((Map) metaObject.getOriginalObject()).get("et");
autoFillUser(metaObject, updateEntity);
}
// 正常只需要更新如下
Date currentDate = new Date(); Date currentDate = new Date();
this.setFieldValByName("updateTime", currentDate, metaObject); if (isExistField("updateTime", metaObject.getOriginalObject())) {
this.setFieldValByName("updateTime", currentDate, metaObject);
}
} }
} }
\ No newline at end of file
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
where where
rs.parent_mrid > 0 rs.parent_mrid > 0
and rs.station_code = #{stationCode} and rs.station_code = #{stationCode}
ORDER BY
rs.rpni DESC, rs.rpn DESC
<if test="top != null and top !=''"> <if test="top != null and top !=''">
limit ${top} limit ${top}
</if> </if>
......
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