Browse Source
feat(baseInformation): 添加SRM零件SKU管理功能
feat(baseInformation): 添加SRM零件SKU管理功能
- 新增SrmPartSku实体类,包含站点、SKU编码、备注、激活状态等字段 - 实现SrmPartSkuController控制器,提供分页查询、保存、更新、删除接口 - 创建SrmPartSkuMapper数据访问层,实现数据库CRUD操作 - 配置SrmPartSkuMapper.xml映射文件,定义SQL查询语句 - 实现SrmPartSkuService业务接口及具体服务类 - 添加参数校验、重复检查、数据标准化等业务逻辑 - 支持按站点、SKU编码、激活状态进行条件查询和分页显示master
6 changed files with 331 additions and 0 deletions
-
47src/main/java/com/xujie/modules/baseInformation/controller/SrmPartSkuController.java
-
27src/main/java/com/xujie/modules/baseInformation/entity/SrmPartSku.java
-
34src/main/java/com/xujie/modules/baseInformation/mapper/SrmPartSkuMapper.java
-
16src/main/java/com/xujie/modules/baseInformation/service/SrmPartSkuService.java
-
119src/main/java/com/xujie/modules/baseInformation/service/impl/SrmPartSkuServiceImpl.java
-
88src/main/resources/mapper/baseInformation/SrmPartSkuMapper.xml
@ -0,0 +1,47 @@ |
|||||
|
package com.xujie.modules.baseInformation.controller; |
||||
|
|
||||
|
import com.xujie.common.utils.PageUtils; |
||||
|
import com.xujie.common.utils.R; |
||||
|
import com.xujie.modules.baseInformation.entity.SrmPartFamily; |
||||
|
import com.xujie.modules.baseInformation.entity.SrmPartSku; |
||||
|
import com.xujie.modules.baseInformation.service.impl.SrmPartSkuServiceImpl; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.web.bind.annotation.PostMapping; |
||||
|
import org.springframework.web.bind.annotation.RequestBody; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
|
||||
|
@RestController |
||||
|
@RequestMapping("/srmPartSku") |
||||
|
public class SrmPartSkuController { |
||||
|
|
||||
|
@Autowired |
||||
|
private SrmPartSkuServiceImpl srmPartSkuService; |
||||
|
|
||||
|
/** |
||||
|
* part_sku 分页查询 |
||||
|
*/ |
||||
|
@RequestMapping("/getPartSkuListPaging") |
||||
|
public R getPartSkuListPaging(@RequestBody SrmPartSku partSku) { |
||||
|
PageUtils page = srmPartSkuService.getPartFamilyListPaging(partSku); |
||||
|
return R.ok().put("data", page); |
||||
|
} |
||||
|
|
||||
|
@PostMapping("/savePartSku") |
||||
|
public R savePartSku(@RequestBody SrmPartSku partSku) { |
||||
|
return srmPartSkuService.savePartSku(partSku); |
||||
|
} |
||||
|
|
||||
|
@PostMapping("/updatePartSku") |
||||
|
public R updatePartSku(@RequestBody SrmPartSku partSku) { |
||||
|
|
||||
|
return srmPartSkuService.updatePartSku(partSku); |
||||
|
} |
||||
|
|
||||
|
@PostMapping("/deletePartSku") |
||||
|
public R deletePartSku(@RequestBody SrmPartSku partSku) { |
||||
|
return srmPartSkuService.deletePartSku(partSku.getSku(), partSku.getSite()); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,27 @@ |
|||||
|
package com.xujie.modules.baseInformation.entity; |
||||
|
|
||||
|
|
||||
|
import com.fasterxml.jackson.annotation.JsonFormat; |
||||
|
import com.xujie.common.utils.QueryPage; |
||||
|
import lombok.Data; |
||||
|
import org.springframework.format.annotation.DateTimeFormat; |
||||
|
|
||||
|
import java.util.Date; |
||||
|
|
||||
|
@Data |
||||
|
public class SrmPartSku extends QueryPage { |
||||
|
|
||||
|
private String site; |
||||
|
|
||||
|
private String sku; |
||||
|
|
||||
|
private String remark; |
||||
|
|
||||
|
private String active; |
||||
|
|
||||
|
private String createBy; |
||||
|
|
||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
||||
|
private Date createDate; |
||||
|
} |
||||
@ -0,0 +1,34 @@ |
|||||
|
package com.xujie.modules.baseInformation.mapper; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
|
import com.xujie.modules.baseInformation.entity.SrmPartFamily; |
||||
|
import com.xujie.modules.baseInformation.entity.SrmPartSku; |
||||
|
import org.apache.ibatis.annotations.Mapper; |
||||
|
import org.apache.ibatis.annotations.Param; |
||||
|
|
||||
|
@Mapper |
||||
|
public interface SrmPartSkuMapper { |
||||
|
IPage<SrmPartSku> selectPartSkuListWithPaging(@Param("page") Page<SrmPartSku> page, @Param("partSku") SrmPartSku partSku); |
||||
|
|
||||
|
/** |
||||
|
* 根据sku和site查询记录 |
||||
|
*/ |
||||
|
SrmPartSku selectPartSkuByCode(@Param("sku") String sku, |
||||
|
@Param("site") String site); |
||||
|
|
||||
|
/** |
||||
|
* 插入SKU记录 |
||||
|
*/ |
||||
|
int insertPartSku(SrmPartSku partSku); |
||||
|
|
||||
|
/** |
||||
|
* 更新SKU记录 |
||||
|
*/ |
||||
|
int updatePartSku(SrmPartSku partSku); |
||||
|
|
||||
|
/** |
||||
|
* 删除SKU记录 |
||||
|
*/ |
||||
|
int deletePartSku(@Param("sku") String sku, @Param("site") String site); |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
package com.xujie.modules.baseInformation.service; |
||||
|
|
||||
|
import com.xujie.common.utils.PageUtils; |
||||
|
import com.xujie.common.utils.R; |
||||
|
import com.xujie.modules.baseInformation.entity.SrmPartSku; |
||||
|
|
||||
|
public interface SrmPartSkuService { |
||||
|
|
||||
|
PageUtils getPartFamilyListPaging(SrmPartSku partSku); |
||||
|
|
||||
|
R savePartSku(SrmPartSku partSku); |
||||
|
|
||||
|
R updatePartSku(SrmPartSku partSku); |
||||
|
|
||||
|
R deletePartSku(String sku, String site); |
||||
|
} |
||||
@ -0,0 +1,119 @@ |
|||||
|
package com.xujie.modules.baseInformation.service.impl; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
|
import com.xujie.common.utils.PageUtils; |
||||
|
import com.xujie.common.utils.R; |
||||
|
import com.xujie.modules.baseInformation.entity.SrmPartFamily; |
||||
|
import com.xujie.modules.baseInformation.entity.SrmPartSku; |
||||
|
import com.xujie.modules.baseInformation.mapper.SrmPartSkuMapper; |
||||
|
import com.xujie.modules.baseInformation.service.SrmPartSkuService; |
||||
|
import org.apache.commons.lang3.StringUtils; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
@Service |
||||
|
public class SrmPartSkuServiceImpl implements SrmPartSkuService { |
||||
|
|
||||
|
@Autowired |
||||
|
private SrmPartSkuMapper srmPartSkuMapper; |
||||
|
|
||||
|
@Override |
||||
|
public PageUtils getPartFamilyListPaging(SrmPartSku partSku) { |
||||
|
Page<SrmPartSku> page = new Page<>(partSku.getPage(), partSku.getLimit()); |
||||
|
IPage<SrmPartSku> iPage = this.srmPartSkuMapper.selectPartSkuListWithPaging(page, partSku); |
||||
|
return new PageUtils(iPage); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public R savePartSku(SrmPartSku partSku) { |
||||
|
// 1. 参数校验 |
||||
|
if (partSku == null) { |
||||
|
return R.error("参数不能为空"); |
||||
|
} |
||||
|
if (StringUtils.isBlank(partSku.getSku())) { |
||||
|
return R.error("SKU 不能为空"); |
||||
|
} |
||||
|
if (StringUtils.isBlank(partSku.getActive())) { |
||||
|
partSku.setActive("Y"); // 默认启用 |
||||
|
} |
||||
|
|
||||
|
SrmPartSku existing = srmPartSkuMapper.selectPartSkuByCode(partSku.getSku(), partSku.getSite()); |
||||
|
if (existing != null) { |
||||
|
return R.error("SKU 已存在"); |
||||
|
} |
||||
|
|
||||
|
int result = srmPartSkuMapper.insertPartSku(partSku); |
||||
|
return result > 0 ? R.ok().put("msg", "新增成功") : R.error("新增失败"); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public R updatePartSku(SrmPartSku partSku) { |
||||
|
// 1. 参数校验 |
||||
|
if (partSku == null) { |
||||
|
return R.error("参数不能为空"); |
||||
|
} |
||||
|
|
||||
|
// 2. 去除空格 |
||||
|
normalizeInput(partSku); |
||||
|
|
||||
|
// 3. 必填字段校验 |
||||
|
if (StringUtils.isBlank(partSku.getSite())) { |
||||
|
return R.error("site 不能为空"); |
||||
|
} |
||||
|
if (StringUtils.isBlank(partSku.getSku())) { |
||||
|
return R.error("SKU 不能为空"); |
||||
|
} |
||||
|
if (StringUtils.isBlank(partSku.getActive())) { |
||||
|
return R.error("是否在用不能为空"); |
||||
|
} |
||||
|
|
||||
|
// 4. 检查记录是否存在 |
||||
|
SrmPartSku existing = srmPartSkuMapper.selectPartSkuByCode(partSku.getSku(), partSku.getSite()); |
||||
|
if (existing == null) { |
||||
|
return R.error("记录不存在"); |
||||
|
} |
||||
|
|
||||
|
// 5. 执行更新 |
||||
|
int result = srmPartSkuMapper.updatePartSku(partSku); |
||||
|
return result > 0 ? R.ok().put("msg", "更新成功") : R.error("更新失败"); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public R deletePartSku(String sku, String site) { |
||||
|
// 1. 参数校验 |
||||
|
sku = StringUtils.trimToEmpty(sku); |
||||
|
site = StringUtils.trimToEmpty(site); |
||||
|
|
||||
|
if (StringUtils.isBlank(site)) { |
||||
|
return R.error("site 不能为空"); |
||||
|
} |
||||
|
if (StringUtils.isBlank(sku)) { |
||||
|
return R.error("SKU 不能为空"); |
||||
|
} |
||||
|
|
||||
|
// 2. 检查记录是否存在 |
||||
|
SrmPartSku existing = srmPartSkuMapper.selectPartSkuByCode(sku, site); |
||||
|
if (existing == null) { |
||||
|
return R.error("记录不存在"); |
||||
|
} |
||||
|
|
||||
|
// 3. 执行删除 |
||||
|
int result = srmPartSkuMapper.deletePartSku(sku, site); |
||||
|
return result > 0 ? R.ok().put("msg", "删除成功") : R.error("删除失败"); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 标准化输入数据,去除前后空格 |
||||
|
*/ |
||||
|
private void normalizeInput(SrmPartSku partSku) { |
||||
|
if (partSku == null) { |
||||
|
return; |
||||
|
} |
||||
|
partSku.setSite(StringUtils.trimToEmpty(partSku.getSite())); |
||||
|
partSku.setSku(StringUtils.trimToEmpty(partSku.getSku())); |
||||
|
partSku.setRemark(StringUtils.trimToEmpty(partSku.getRemark())); |
||||
|
partSku.setActive(StringUtils.trimToEmpty(partSku.getActive())); |
||||
|
partSku.setCreateBy(StringUtils.trimToEmpty(partSku.getCreateBy())); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,88 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||
|
<mapper namespace="com.xujie.modules.baseInformation.mapper.SrmPartSkuMapper"> |
||||
|
|
||||
|
|
||||
|
<resultMap id="PartSkuResultMap" type="com.xujie.modules.baseInformation.entity.SrmPartSku"> |
||||
|
<result property="site" column="site"/> |
||||
|
<result property="sku" column="sku"/> |
||||
|
<result property="remark" column="remark"/> |
||||
|
<result property="active" column="active"/> |
||||
|
<result property="createDate" column="create_date"/> |
||||
|
<result property="createBy" column="create_by"/> |
||||
|
</resultMap> |
||||
|
|
||||
|
<sql id="PartSkuColumnList"> |
||||
|
site, |
||||
|
sku, |
||||
|
remark, |
||||
|
active, |
||||
|
create_date, |
||||
|
create_by |
||||
|
</sql> |
||||
|
|
||||
|
<select id="selectPartSkuListWithPaging" |
||||
|
resultType="com.xujie.modules.baseInformation.entity.SrmPartSku"> |
||||
|
select |
||||
|
<include refid="PartSkuColumnList"/> |
||||
|
from part_sku |
||||
|
where |
||||
|
<if test="partSku.site != null and partSku.site != ''"> |
||||
|
site = #{partSku.site} |
||||
|
</if> |
||||
|
<if test="partSku.sku != null and partSku.sku != ''"> |
||||
|
and sku = #{partSku.sku} |
||||
|
</if> |
||||
|
<if test="partSku.active != null and partSku.active != ''"> |
||||
|
and active = #{partSku.active} |
||||
|
</if> |
||||
|
order by sku |
||||
|
</select> |
||||
|
|
||||
|
<!-- 根据sku和site查询记录 --> |
||||
|
<select id="selectPartSkuByCode" resultType="com.xujie.modules.baseInformation.entity.SrmPartSku"> |
||||
|
SELECT |
||||
|
<include refid="PartSkuColumnList"/> |
||||
|
FROM part_sku |
||||
|
WHERE site = #{site} |
||||
|
AND sku = #{sku} |
||||
|
</select> |
||||
|
|
||||
|
<!-- 插入SKU记录 --> |
||||
|
<insert id="insertPartSku"> |
||||
|
INSERT INTO part_sku ( |
||||
|
site, |
||||
|
sku, |
||||
|
remark, |
||||
|
active, |
||||
|
create_date, |
||||
|
create_by |
||||
|
) VALUES ( |
||||
|
#{site}, |
||||
|
#{sku}, |
||||
|
#{remark}, |
||||
|
#{active}, |
||||
|
GETDATE(), |
||||
|
#{createBy} |
||||
|
) |
||||
|
</insert> |
||||
|
|
||||
|
<!-- 更新SKU记录 --> |
||||
|
<update id="updatePartSku"> |
||||
|
UPDATE part_sku |
||||
|
<set> |
||||
|
remark = #{remark}, |
||||
|
active = #{active}, |
||||
|
create_by = #{createBy} |
||||
|
</set> |
||||
|
WHERE site = #{site} |
||||
|
AND sku = #{sku} |
||||
|
</update> |
||||
|
|
||||
|
<!-- 删除SKU记录 --> |
||||
|
<delete id="deletePartSku"> |
||||
|
DELETE FROM part_sku |
||||
|
WHERE site = #{site} |
||||
|
AND sku = #{sku} |
||||
|
</delete> |
||||
|
</mapper> |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue