把商品扩展字段表改为带租户id的模式

This commit is contained in:
jishenghua 2025-03-25 23:37:31 +08:00
parent ef587ae8f9
commit a9edd44f6c
10 changed files with 190 additions and 37 deletions

View File

@ -540,6 +540,7 @@ CREATE TABLE `jsh_material_property` (
`enabled` bit(1) DEFAULT NULL COMMENT '是否启用',
`sort` varchar(10) DEFAULT NULL COMMENT '排序',
`another_name` varchar(50) DEFAULT NULL COMMENT '别名',
`tenant_id` bigint(20) DEFAULT NULL COMMENT '租户id',
`delete_flag` varchar(1) DEFAULT '0' COMMENT '删除标记0未删除1删除',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COMMENT='产品扩展字段表';
@ -547,10 +548,6 @@ CREATE TABLE `jsh_material_property` (
-- ----------------------------
-- Records of jsh_material_property
-- ----------------------------
INSERT INTO `jsh_material_property` VALUES ('1', '制造商', '', '01', '制造商', '0');
INSERT INTO `jsh_material_property` VALUES ('2', '自定义1', '', '02', '自定义1', '0');
INSERT INTO `jsh_material_property` VALUES ('3', '自定义2', '', '03', '自定义2', '0');
INSERT INTO `jsh_material_property` VALUES ('4', '自定义3', '', '04', '自定义3', '0');
-- ----------------------------
-- Table structure for jsh_msg

View File

@ -1635,4 +1635,12 @@ update jsh_function set name='多单位' where number='010103';
-- by jishenghua
-- 给地址字段调整长度
-- --------------------------------------------------------
alter table jsh_supplier change address address varchar(100) DEFAULT NULL COMMENT '地址';
alter table jsh_supplier change address address varchar(100) DEFAULT NULL COMMENT '地址';
-- --------------------------------------------------------
-- 时间 2025年3月25日
-- by jishenghua
-- 给产品扩展字段表增加租户id字段
-- 另外注意:需要手动把商品属性菜单分配给租户角色
-- --------------------------------------------------------
alter table jsh_material_property add tenant_id bigint(20) DEFAULT NULL COMMENT '租户id' after another_name;

View File

@ -54,9 +54,8 @@ public class TenantConfig {
Long tenantId = Tools.getTenantIdByToken(token);
if (tenantId!=0L) {
// 这里可以判断是否过滤表
if ("jsh_material_property".equals(tableName) || "jsh_sequence".equals(tableName)
|| "jsh_function".equals(tableName) || "jsh_platform_config".equals(tableName)
|| "jsh_tenant".equals(tableName)) {
if ("jsh_sequence".equals(tableName) || "jsh_function".equals(tableName)
|| "jsh_platform_config".equals(tableName) || "jsh_tenant".equals(tableName)) {
res = true;
} else {
res = false;

View File

@ -27,8 +27,8 @@ import static com.jsh.erp.utils.ResponseJsonUtil.returnStr;
/**
* Description
*
* @Author: qiankunpingtai
* @Date: 2019/3/29 15:24
* @Author: jsh
* @Date: 2025/3/25 15:24
*/
@RestController
@RequestMapping(value = "/materialProperty")
@ -79,6 +79,23 @@ public class MaterialPropertyController extends BaseController {
return returnStr(objectMap, update);
}
@PostMapping(value = "/addOrUpdate")
@ApiOperation(value = "新增或修改")
public String addOrUpdate(@RequestBody JSONObject obj, HttpServletRequest request)throws Exception {
Map<String, Object> objectMap = new HashMap<>();
String nativeName = obj.getString("nativeName");
String anotherName = obj.getString("anotherName");
boolean exist = materialPropertyService.checkIsNativeNameExist(nativeName);
int res;
if(!exist) {
obj.put("id", null);
res = materialPropertyService.insertMaterialProperty(obj, request);
} else {
res = materialPropertyService.updateMaterialPropertyByNativeName(nativeName, anotherName);
}
return returnStr(objectMap, res);
}
@DeleteMapping(value = "/delete")
@ApiOperation(value = "删除")
public String deleteResource(@RequestParam("id") Long id, HttpServletRequest request)throws Exception {

View File

@ -11,6 +11,8 @@ public class MaterialProperty {
private String anotherName;
private Long tenantId;
private String deleteFlag;
public Long getId() {
@ -53,6 +55,14 @@ public class MaterialProperty {
this.anotherName = anotherName == null ? null : anotherName.trim();
}
public Long getTenantId() {
return tenantId;
}
public void setTenantId(Long tenantId) {
this.tenantId = tenantId;
}
public String getDeleteFlag() {
return deleteFlag;
}

View File

@ -434,6 +434,66 @@ public class MaterialPropertyExample {
return (Criteria) this;
}
public Criteria andTenantIdIsNull() {
addCriterion("tenant_id is null");
return (Criteria) this;
}
public Criteria andTenantIdIsNotNull() {
addCriterion("tenant_id is not null");
return (Criteria) this;
}
public Criteria andTenantIdEqualTo(Long value) {
addCriterion("tenant_id =", value, "tenantId");
return (Criteria) this;
}
public Criteria andTenantIdNotEqualTo(Long value) {
addCriterion("tenant_id <>", value, "tenantId");
return (Criteria) this;
}
public Criteria andTenantIdGreaterThan(Long value) {
addCriterion("tenant_id >", value, "tenantId");
return (Criteria) this;
}
public Criteria andTenantIdGreaterThanOrEqualTo(Long value) {
addCriterion("tenant_id >=", value, "tenantId");
return (Criteria) this;
}
public Criteria andTenantIdLessThan(Long value) {
addCriterion("tenant_id <", value, "tenantId");
return (Criteria) this;
}
public Criteria andTenantIdLessThanOrEqualTo(Long value) {
addCriterion("tenant_id <=", value, "tenantId");
return (Criteria) this;
}
public Criteria andTenantIdIn(List<Long> values) {
addCriterion("tenant_id in", values, "tenantId");
return (Criteria) this;
}
public Criteria andTenantIdNotIn(List<Long> values) {
addCriterion("tenant_id not in", values, "tenantId");
return (Criteria) this;
}
public Criteria andTenantIdBetween(Long value1, Long value2) {
addCriterion("tenant_id between", value1, value2, "tenantId");
return (Criteria) this;
}
public Criteria andTenantIdNotBetween(Long value1, Long value2) {
addCriterion("tenant_id not between", value1, value2, "tenantId");
return (Criteria) this;
}
public Criteria andDeleteFlagIsNull() {
addCriterion("delete_flag is null");
return (Criteria) this;

View File

@ -13,4 +13,10 @@ public interface MaterialPropertyMapperEx {
@Param("name") String name);
int batchDeleteMaterialPropertyByIds(@Param("updateTime") Date updateTime, @Param("updater") Long updater, @Param("ids") String ids[]);
int getCountByNativeName(@Param("nativeName") String nativeName);
void updateMaterialPropertyByNativeName(
@Param("nativeName") String nativeName,
@Param("anotherName") String anotherName);
}

View File

@ -18,8 +18,7 @@ import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.*;
@Service
public class MaterialPropertyService {
@ -58,11 +57,34 @@ public class MaterialPropertyService {
}
public List<MaterialProperty> select(String name)throws Exception {
List<MaterialProperty> list=null;
List<MaterialProperty> list = new ArrayList<>();
try{
if(BusinessConstants.DEFAULT_MANAGER.equals(userService.getCurrentUser().getLoginName())) {
PageUtils.startPage();
list = materialPropertyMapperEx.selectByConditionMaterialProperty(name);
MaterialProperty mp1 = new MaterialProperty();
MaterialProperty mp2 = new MaterialProperty();
MaterialProperty mp3 = new MaterialProperty();
mp1.setId(1L);
mp1.setNativeName("扩展1");
mp1.setAnotherName("扩展1");
list.add(mp1);
mp2.setId(2L);
mp2.setNativeName("扩展2");
mp2.setAnotherName("扩展2");
list.add(mp2);
mp3.setId(3L);
mp3.setNativeName("扩展3");
mp3.setAnotherName("扩展3");
list.add(mp3);
PageUtils.startPage();
List<MaterialProperty> mpList = materialPropertyMapperEx.selectByConditionMaterialProperty(name);
Map<String, String> mpMap = new HashMap<>();
for(MaterialProperty mp: mpList) {
mpMap.put(mp.getNativeName(), mp.getAnotherName());
}
//给list里面的别名和排序做更新
for(MaterialProperty item: list) {
if(mpMap.get(item.getNativeName())!=null) {
item.setAnotherName(mpMap.get(item.getNativeName()));
}
}
}catch(Exception e){
JshException.readFail(logger, e);
@ -75,11 +97,9 @@ public class MaterialPropertyService {
MaterialProperty materialProperty = JSONObject.parseObject(obj.toJSONString(), MaterialProperty.class);
int result=0;
try{
if(BusinessConstants.DEFAULT_MANAGER.equals(userService.getCurrentUser().getLoginName())) {
result = materialPropertyMapper.insertSelective(materialProperty);
logService.insertLog("商品属性",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(materialProperty.getNativeName()).toString(), request);
}
result = materialPropertyMapper.insertSelective(materialProperty);
logService.insertLog("商品属性",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(materialProperty.getNativeName()).toString(), request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
@ -91,11 +111,9 @@ public class MaterialPropertyService {
MaterialProperty materialProperty = JSONObject.parseObject(obj.toJSONString(), MaterialProperty.class);
int result=0;
try{
if(BusinessConstants.DEFAULT_MANAGER.equals(userService.getCurrentUser().getLoginName())) {
result = materialPropertyMapper.updateByPrimaryKeySelective(materialProperty);
logService.insertLog("商品属性",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(materialProperty.getNativeName()).toString(), request);
}
result = materialPropertyMapper.updateByPrimaryKeySelective(materialProperty);
logService.insertLog("商品属性",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(materialProperty.getNativeName()).toString(), request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
@ -118,12 +136,10 @@ public class MaterialPropertyService {
String [] idArray=ids.split(",");
int result=0;
try{
if(BusinessConstants.DEFAULT_MANAGER.equals(userService.getCurrentUser().getLoginName())) {
result = materialPropertyMapperEx.batchDeleteMaterialPropertyByIds(new Date(), userInfo == null ? null : userInfo.getId(), idArray);
logService.insertLog("商品属性",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_DELETE).append(ids).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
}
result = materialPropertyMapperEx.batchDeleteMaterialPropertyByIds(new Date(), userInfo == null ? null : userInfo.getId(), idArray);
logService.insertLog("商品属性",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_DELETE).append(ids).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
}catch(Exception e){
JshException.writeFail(logger, e);
}
@ -133,4 +149,14 @@ public class MaterialPropertyService {
public int checkIsNameExist(Long id, String name)throws Exception {
return 0;
}
public boolean checkIsNativeNameExist(String nativeName) {
int count = materialPropertyMapperEx.getCountByNativeName(nativeName);
return count>0;
}
public int updateMaterialPropertyByNativeName(String nativeName, String anotherName) {
materialPropertyMapperEx.updateMaterialPropertyByNativeName(nativeName, anotherName);
return 1;
}
}

View File

@ -7,6 +7,7 @@
<result column="enabled" jdbcType="BIT" property="enabled" />
<result column="sort" jdbcType="VARCHAR" property="sort" />
<result column="another_name" jdbcType="VARCHAR" property="anotherName" />
<result column="tenant_id" jdbcType="BIGINT" property="tenantId" />
<result column="delete_flag" jdbcType="VARCHAR" property="deleteFlag" />
</resultMap>
<sql id="Example_Where_Clause">
@ -68,7 +69,7 @@
</where>
</sql>
<sql id="Base_Column_List">
id, native_name, enabled, sort, another_name, delete_flag
id, native_name, enabled, sort, another_name, tenant_id, delete_flag
</sql>
<select id="selectByExample" parameterType="com.jsh.erp.datasource.entities.MaterialPropertyExample" resultMap="BaseResultMap">
select
@ -102,11 +103,11 @@
</delete>
<insert id="insert" parameterType="com.jsh.erp.datasource.entities.MaterialProperty">
insert into jsh_material_property (id, native_name, enabled,
sort, another_name, delete_flag
)
sort, another_name, tenant_id,
delete_flag)
values (#{id,jdbcType=BIGINT}, #{nativeName,jdbcType=VARCHAR}, #{enabled,jdbcType=BIT},
#{sort,jdbcType=VARCHAR}, #{anotherName,jdbcType=VARCHAR}, #{deleteFlag,jdbcType=VARCHAR}
)
#{sort,jdbcType=VARCHAR}, #{anotherName,jdbcType=VARCHAR}, #{tenantId,jdbcType=BIGINT},
#{deleteFlag,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="com.jsh.erp.datasource.entities.MaterialProperty">
insert into jsh_material_property
@ -126,6 +127,9 @@
<if test="anotherName != null">
another_name,
</if>
<if test="tenantId != null">
tenant_id,
</if>
<if test="deleteFlag != null">
delete_flag,
</if>
@ -146,6 +150,9 @@
<if test="anotherName != null">
#{anotherName,jdbcType=VARCHAR},
</if>
<if test="tenantId != null">
#{tenantId,jdbcType=BIGINT},
</if>
<if test="deleteFlag != null">
#{deleteFlag,jdbcType=VARCHAR},
</if>
@ -175,6 +182,9 @@
<if test="record.anotherName != null">
another_name = #{record.anotherName,jdbcType=VARCHAR},
</if>
<if test="record.tenantId != null">
tenant_id = #{record.tenantId,jdbcType=BIGINT},
</if>
<if test="record.deleteFlag != null">
delete_flag = #{record.deleteFlag,jdbcType=VARCHAR},
</if>
@ -190,6 +200,7 @@
enabled = #{record.enabled,jdbcType=BIT},
sort = #{record.sort,jdbcType=VARCHAR},
another_name = #{record.anotherName,jdbcType=VARCHAR},
tenant_id = #{record.tenantId,jdbcType=BIGINT},
delete_flag = #{record.deleteFlag,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
@ -210,6 +221,9 @@
<if test="anotherName != null">
another_name = #{anotherName,jdbcType=VARCHAR},
</if>
<if test="tenantId != null">
tenant_id = #{tenantId,jdbcType=BIGINT},
</if>
<if test="deleteFlag != null">
delete_flag = #{deleteFlag,jdbcType=VARCHAR},
</if>
@ -222,6 +236,7 @@
enabled = #{enabled,jdbcType=BIT},
sort = #{sort,jdbcType=VARCHAR},
another_name = #{anotherName,jdbcType=VARCHAR},
tenant_id = #{tenantId,jdbcType=BIGINT},
delete_flag = #{deleteFlag,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT}
</update>

View File

@ -10,6 +10,7 @@
and native_name like #{bindName}
</if>
and ifnull(delete_flag,'0') !='1'
order by native_name asc
</select>
<update id="batchDeleteMaterialPropertyByIds">
@ -22,4 +23,18 @@
</foreach>
)
</update>
<select id="getCountByNativeName" resultType="java.lang.Integer">
select count(1)
from jsh_material_property
where native_name = #{nativeName}
and ifnull(delete_flag,'0') !='1'
</select>
<update id="updateMaterialPropertyByNativeName">
update jsh_material_property
set another_name = #{anotherName}
where native_name = #{nativeName}
and ifnull(delete_flag,'0') !='1'
</update>
</mapper>