完成解绑与绑定

This commit is contained in:
liumingxiy 2024-11-15 17:28:21 +08:00
parent 3edc3317e9
commit 2f407f2451
5 changed files with 311 additions and 57 deletions

View File

@ -0,0 +1,61 @@
package com.ktg.mes.md.mapper;
import com.ktg.mes.wm.domain.UcmCtMaterial;
import java.util.List;
/**
* 料箱物料绑定Mapper接口
*
* @author yinjinlu
* @date 2024-11-15
*/
public interface UcmCtMaterialMapper2 {
/**
* 查询料箱物料绑定
*
* @param ctMaterialId 料箱物料绑定主键
* @return 料箱物料绑定
*/
public UcmCtMaterial selectUcmCtMaterialByCtMaterialId(Long ctMaterialId);
/**
* 查询料箱物料绑定列表
*
* @param ucmCtMaterial 料箱物料绑定
* @return 料箱物料绑定集合
*/
public List<UcmCtMaterial> selectUcmCtMaterialList(UcmCtMaterial ucmCtMaterial);
/**
* 新增料箱物料绑定
*
* @param ucmCtMaterial 料箱物料绑定
* @return 结果
*/
public int insertUcmCtMaterial(UcmCtMaterial ucmCtMaterial);
/**
* 修改料箱物料绑定
*
* @param ucmCtMaterial 料箱物料绑定
* @return 结果
*/
public int updateUcmCtMaterial(UcmCtMaterial ucmCtMaterial);
/**
* 删除料箱物料绑定
*
* @param ctMaterialId 料箱物料绑定主键
* @return 结果
*/
public int deleteUcmCtMaterialByCtMaterialId(Long ctMaterialId);
/**
* 批量删除料箱物料绑定
*
* @param ctMaterialIds 需要删除的数据主键集合
* @return 结果
*/
public int deleteUcmCtMaterialByCtMaterialIds(Long[] ctMaterialIds);
}

View File

@ -1,36 +1,29 @@
package com.ktg.mes.wm.controller;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktg.common.annotation.Log;
import com.ktg.common.core.controller.BaseController;
import com.ktg.common.core.domain.AjaxResult;
import com.ktg.common.core.page.TableDataInfo;
import com.ktg.common.enums.BusinessType;
import com.ktg.common.utils.poi.ExcelUtil;
import com.ktg.mes.wm.domain.UcmCtBase;
import com.ktg.mes.wm.service.IUcmCtBaseService;
import com.ktg.common.utils.poi.ExcelUtil;
import com.ktg.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* 料箱管理Controller
*
*
* @author yinjinlu
* @date 2024-10-31
*/
@RestController
@RequestMapping("/wm/ctBase")
public class UcmCtBaseController extends BaseController
{
public class UcmCtBaseController extends BaseController {
@Autowired
private IUcmCtBaseService ucmCtBaseService;
@ -39,8 +32,7 @@ public class UcmCtBaseController extends BaseController
*/
@PreAuthorize("@ss.hasPermi('wm:ctBase:list')")
@GetMapping("/list")
public TableDataInfo list(UcmCtBase ucmCtBase)
{
public TableDataInfo list(UcmCtBase ucmCtBase) {
startPage();
List<UcmCtBase> list = ucmCtBaseService.selectUcmCtBaseList(ucmCtBase);
return getDataTable(list);
@ -52,8 +44,7 @@ public class UcmCtBaseController extends BaseController
@PreAuthorize("@ss.hasPermi('wm:ctBase:export')")
@Log(title = "料箱管理", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, UcmCtBase ucmCtBase)
{
public void export(HttpServletResponse response, UcmCtBase ucmCtBase) {
List<UcmCtBase> list = ucmCtBaseService.selectUcmCtBaseList(ucmCtBase);
ExcelUtil<UcmCtBase> util = new ExcelUtil<UcmCtBase>(UcmCtBase.class);
util.exportExcel(response, list, "料箱管理数据");
@ -64,8 +55,7 @@ public class UcmCtBaseController extends BaseController
*/
@PreAuthorize("@ss.hasPermi('wm:ctBase:query')")
@GetMapping(value = "/{ctBaseId}")
public AjaxResult getInfo(@PathVariable("ctBaseId") String ctBaseId)
{
public AjaxResult getInfo(@PathVariable("ctBaseId") String ctBaseId) {
return AjaxResult.success(ucmCtBaseService.selectUcmCtBaseByCtBaseId(ctBaseId));
}
@ -75,8 +65,7 @@ public class UcmCtBaseController extends BaseController
@PreAuthorize("@ss.hasPermi('wm:ctBase:add')")
@Log(title = "料箱管理", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody UcmCtBase ucmCtBase)
{
public AjaxResult add(@RequestBody UcmCtBase ucmCtBase) {
ucmCtBase.setCreateBy(getUsername());
return toAjax(ucmCtBaseService.insertUcmCtBase(ucmCtBase));
}
@ -87,8 +76,7 @@ public class UcmCtBaseController extends BaseController
@PreAuthorize("@ss.hasPermi('wm:ctBase:edit')")
@Log(title = "料箱管理", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody UcmCtBase ucmCtBase)
{
public AjaxResult edit(@RequestBody UcmCtBase ucmCtBase) {
ucmCtBase.setUpdateBy(getUsername());
return toAjax(ucmCtBaseService.updateUcmCtBase(ucmCtBase));
}
@ -98,9 +86,28 @@ public class UcmCtBaseController extends BaseController
*/
@PreAuthorize("@ss.hasPermi('wm:ctBase:remove')")
@Log(title = "料箱管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{ctBaseIds}")
public AjaxResult remove(@PathVariable String[] ctBaseIds)
{
@DeleteMapping("/{ctBaseIds}")
public AjaxResult remove(@PathVariable String[] ctBaseIds) {
return toAjax(ucmCtBaseService.deleteUcmCtBaseByCtBaseIds(ctBaseIds));
}
@PreAuthorize("@ss.hasPermi('wm:ctBase:edit')")
@Log(title = "料箱管理", businessType = BusinessType.UPDATE)
@PutMapping("/bind/{boxCode}/{itemCode}")
public AjaxResult bind(
@PathVariable String boxCode,
@PathVariable String itemCode
) {
return toAjax(ucmCtBaseService.bindUcmCtBase(boxCode, itemCode));
}
@PreAuthorize("@ss.hasPermi('wm:ctBase:edit')")
@Log(title = "料箱管理", businessType = BusinessType.UPDATE)
@PutMapping("/unbind/{boxCode}/{itemCode}")
public AjaxResult unbind(
@PathVariable String boxCode,
@PathVariable String itemCode
) {
return toAjax(ucmCtBaseService.unbindUcmCtBase(boxCode, itemCode));
}
}

View File

@ -1,8 +1,9 @@
package com.ktg.mes.wm.service;
import java.util.List;
import com.ktg.mes.wm.domain.UcmCtBase;
import java.util.List;
/**
* 料箱管理Service接口
*
@ -53,9 +54,13 @@ public interface IUcmCtBaseService
/**
* 删除料箱管理信息
*
*
* @param ctBaseId 料箱管理主键
* @return 结果
*/
public int deleteUcmCtBaseByCtBaseId(String ctBaseId);
int bindUcmCtBase(String boxCode, String itemCode);
int unbindUcmCtBase(String boxCode, String itemCode);
}

View File

@ -1,61 +1,69 @@
package com.ktg.mes.wm.service.impl;
import java.util.List;
import com.ktg.common.utils.DateUtils;
import com.ktg.mes.md.domain.BaseKnife;
import com.ktg.mes.md.mapper.BaseKnifeMapper;
import com.ktg.mes.md.mapper.UcmCtMaterialMapper2;
import com.ktg.mes.wm.domain.UcmCtBase;
import com.ktg.mes.wm.domain.UcmCtMaterial;
import com.ktg.mes.wm.mapper.UcmCtBaseMapper;
import com.ktg.mes.wm.service.IUcmCtBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ktg.mes.wm.mapper.UcmCtBaseMapper;
import com.ktg.mes.wm.domain.UcmCtBase;
import com.ktg.mes.wm.service.IUcmCtBaseService;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
import static org.apache.commons.lang3.SystemUtils.getUserName;
/**
* 料箱管理Service业务层处理
*
*
* @author yinjinlu
* @date 2024-10-31
*/
@Service
public class UcmCtBaseServiceImpl implements IUcmCtBaseService
{
public class UcmCtBaseServiceImpl implements IUcmCtBaseService {
@Autowired
private UcmCtBaseMapper ucmCtBaseMapper;
@Autowired
private BaseKnifeMapper baseKnifeMapper;
@Autowired
private UcmCtMaterialMapper2 ucmCtMaterialMapper2;
/**
* 查询料箱管理
*
*
* @param ctBaseId 料箱管理主键
* @return 料箱管理
*/
@Override
public UcmCtBase selectUcmCtBaseByCtBaseId(String ctBaseId)
{
public UcmCtBase selectUcmCtBaseByCtBaseId(String ctBaseId) {
return ucmCtBaseMapper.selectUcmCtBaseByCtBaseId(ctBaseId);
}
/**
* 查询料箱管理列表
*
*
* @param ucmCtBase 料箱管理
* @return 料箱管理
*/
@Override
public List<UcmCtBase> selectUcmCtBaseList(UcmCtBase ucmCtBase)
{
public List<UcmCtBase> selectUcmCtBaseList(UcmCtBase ucmCtBase) {
return ucmCtBaseMapper.selectUcmCtBaseList(ucmCtBase);
}
/**
* 新增料箱管理
*
*
* @param ucmCtBase 料箱管理
* @return 结果
*/
@Override
public int insertUcmCtBase(UcmCtBase ucmCtBase)
{
public int insertUcmCtBase(UcmCtBase ucmCtBase) {
ucmCtBase.setCreateTime(DateUtils.getNowDate());
ucmCtBase.setCreateBy(getUserName());
int ctBaseId = ucmCtBaseMapper.insertUcmCtBase(ucmCtBase);
@ -72,13 +80,12 @@ public class UcmCtBaseServiceImpl implements IUcmCtBaseService
/**
* 修改料箱管理
*
*
* @param ucmCtBase 料箱管理
* @return 结果
*/
@Override
public int updateUcmCtBase(UcmCtBase ucmCtBase)
{
public int updateUcmCtBase(UcmCtBase ucmCtBase) {
ucmCtBase.setUpdateTime(DateUtils.getNowDate());
ucmCtBase.setUpdateBy(getUserName());
ucmCtBaseMapper.deleteUcmCtMaterialByCtBaseId(ucmCtBase.getCtBaseId());
@ -95,25 +102,83 @@ public class UcmCtBaseServiceImpl implements IUcmCtBaseService
/**
* 批量删除料箱管理
*
*
* @param ctBaseIds 需要删除的料箱管理主键
* @return 结果
*/
@Override
public int deleteUcmCtBaseByCtBaseIds(String[] ctBaseIds)
{
public int deleteUcmCtBaseByCtBaseIds(String[] ctBaseIds) {
return ucmCtBaseMapper.deleteUcmCtBaseByCtBaseIds(ctBaseIds);
}
/**
* 删除料箱管理信息
*
*
* @param ctBaseId 料箱管理主键
* @return 结果
*/
@Override
public int deleteUcmCtBaseByCtBaseId(String ctBaseId)
{
public int deleteUcmCtBaseByCtBaseId(String ctBaseId) {
return ucmCtBaseMapper.deleteUcmCtBaseByCtBaseId(ctBaseId);
}
@Transactional
@Override
public int bindUcmCtBase(String boxCode, String itemCode) {
UcmCtBase ucmCtBaseQuery = new UcmCtBase();
ucmCtBaseQuery.setCode(boxCode);
List<UcmCtBase> ucmCtBaseList = ucmCtBaseMapper.selectUcmCtBaseList(ucmCtBaseQuery);
if (ucmCtBaseList.isEmpty())
throw new RuntimeException("绑定失败,该料箱不存在");
BaseKnife baseKnifeQuery = new BaseKnife();
baseKnifeQuery.setRfid(itemCode);
List<BaseKnife> baseKnifeList = baseKnifeMapper.selectBaseKnifeList(baseKnifeQuery);
if (baseKnifeList.isEmpty())
throw new RuntimeException("绑定失败,该物料不存在");
UcmCtMaterial ucmCtMaterialQuery = new UcmCtMaterial();
ucmCtMaterialQuery.setCtBaseId(Long.parseLong(ucmCtBaseList.get(0).getCtBaseId()));
ucmCtMaterialQuery.setBaseKnifeId(baseKnifeList.get(0).getBaseKnifeId());
List<UcmCtMaterial> ucmCtMaterialList = ucmCtMaterialMapper2.selectUcmCtMaterialList(ucmCtMaterialQuery);
if (!ucmCtMaterialList.isEmpty())
throw new RuntimeException("解绑失败,该物料已经绑定该料箱");
UcmCtMaterial ucmCtMaterial = new UcmCtMaterial();
ucmCtMaterial.setCtBaseId(Long.parseLong(ucmCtBaseList.get(0).getCtBaseId()));
ucmCtMaterial.setBaseKnifeId(baseKnifeList.get(0).getBaseKnifeId());
ucmCtMaterial.setCreateTime(new Date(System.currentTimeMillis()));
ucmCtMaterialMapper2.insertUcmCtMaterial(ucmCtMaterial);
return 1;
}
@Transactional
@Override
public int unbindUcmCtBase(String boxCode, String itemCode) {
UcmCtBase ucmCtBaseQuery = new UcmCtBase();
ucmCtBaseQuery.setCode(boxCode);
List<UcmCtBase> ucmCtBaseList = ucmCtBaseMapper.selectUcmCtBaseList(ucmCtBaseQuery);
if (ucmCtBaseList.isEmpty())
throw new RuntimeException("解绑失败,该料箱不存在");
BaseKnife baseKnifeQuery = new BaseKnife();
baseKnifeQuery.setRfid(itemCode);
List<BaseKnife> baseKnifeList = baseKnifeMapper.selectBaseKnifeList(baseKnifeQuery);
if (baseKnifeList.isEmpty())
throw new RuntimeException("解绑失败,该物料不存在");
UcmCtMaterial ucmCtMaterialQuery = new UcmCtMaterial();
ucmCtMaterialQuery.setCtBaseId(Long.parseLong(ucmCtBaseList.get(0).getCtBaseId()));
ucmCtMaterialQuery.setBaseKnifeId(baseKnifeList.get(0).getBaseKnifeId());
List<UcmCtMaterial> ucmCtMaterialList = ucmCtMaterialMapper2.selectUcmCtMaterialList(ucmCtMaterialQuery);
if (ucmCtMaterialList.isEmpty())
throw new RuntimeException("解绑失败,该物料并未绑定该料箱");
ucmCtMaterialList.forEach(item -> {
ucmCtMaterialMapper2.deleteUcmCtMaterialByCtMaterialId(item.getCtMaterialId());
});
return ucmCtMaterialList.size();
}
}

View File

@ -0,0 +1,116 @@
<?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.ktg.mes.md.mapper.UcmCtMaterialMapper2">
<resultMap type="UcmCtMaterial" id="UcmCtMaterialResult">
<result property="ctMaterialId" column="CT_MATERIAL_ID"/>
<result property="ctBaseId" column="CT_BASE_ID"/>
<result property="baseKnifeId" column="BASE_KNIFE_ID"/>
<result property="remark" column="REMARK"/>
<result property="attr1" column="ATTR1"/>
<result property="attr2" column="ATTR2"/>
<result property="attr3" column="ATTR3"/>
<result property="attr4" column="ATTR4"/>
<result property="createBy" column="CREATE_BY"/>
<result property="createTime" column="CREATE_TIME"/>
<result property="updateBy" column="UPDATE_BY"/>
<result property="updateTime" column="UPDATE_TIME"/>
</resultMap>
<sql id="selectUcmCtMaterialVo">
select CT_MATERIAL_ID,
CT_BASE_ID,
BASE_KNIFE_ID,
REMARK,
ATTR1,
ATTR2,
ATTR3,
ATTR4,
CREATE_BY,
CREATE_TIME,
UPDATE_BY,
UPDATE_TIME
from UCM_CT_MATERIAL
</sql>
<select id="selectUcmCtMaterialList" parameterType="UcmCtMaterial" resultMap="UcmCtMaterialResult">
<include refid="selectUcmCtMaterialVo"/>
<where>
<if test="ctBaseId != null ">and CT_BASE_ID = #{ctBaseId}</if>
<if test="baseKnifeId != null ">and BASE_KNIFE_ID = #{baseKnifeId}</if>
<if test="remark != null and remark != ''">and REMARK = #{remark}</if>
<if test="createBy != null and createBy != ''">and CREATE_BY = #{createBy}</if>
<if test="createTime != null ">and CREATE_TIME = #{createTime}</if>
<if test="updateBy != null and updateBy != ''">and UPDATE_BY = #{updateBy}</if>
<if test="updateTime != null ">and UPDATE_TIME = #{updateTime}</if>
</where>
</select>
<select id="selectUcmCtMaterialByCtMaterialId" parameterType="Long" resultMap="UcmCtMaterialResult">
<include refid="selectUcmCtMaterialVo"/>
where CT_MATERIAL_ID = #{ctMaterialId}
</select>
<insert id="insertUcmCtMaterial" parameterType="UcmCtMaterial" useGeneratedKeys="true" keyProperty="ctMaterialId">
insert into UCM_CT_MATERIAL
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="ctBaseId != null">CT_BASE_ID,</if>
<if test="baseKnifeId != null">BASE_KNIFE_ID,</if>
<if test="remark != null">REMARK,</if>
<if test="attr1 != null">ATTR1,</if>
<if test="attr2 != null">ATTR2,</if>
<if test="attr3 != null">ATTR3,</if>
<if test="attr4 != null">ATTR4,</if>
<if test="createBy != null">CREATE_BY,</if>
<if test="createTime != null">CREATE_TIME,</if>
<if test="updateBy != null">UPDATE_BY,</if>
<if test="updateTime != null">UPDATE_TIME,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="ctBaseId != null">#{ctBaseId},</if>
<if test="baseKnifeId != null">#{baseKnifeId},</if>
<if test="remark != null">#{remark},</if>
<if test="attr1 != null">#{attr1},</if>
<if test="attr2 != null">#{attr2},</if>
<if test="attr3 != null">#{attr3},</if>
<if test="attr4 != null">#{attr4},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
</trim>
</insert>
<update id="updateUcmCtMaterial" parameterType="UcmCtMaterial">
update UCM_CT_MATERIAL
<trim prefix="SET" suffixOverrides=",">
<if test="ctBaseId != null">CT_BASE_ID = #{ctBaseId},</if>
<if test="baseKnifeId != null">BASE_KNIFE_ID = #{baseKnifeId},</if>
<if test="remark != null">REMARK = #{remark},</if>
<if test="attr1 != null">ATTR1 = #{attr1},</if>
<if test="attr2 != null">ATTR2 = #{attr2},</if>
<if test="attr3 != null">ATTR3 = #{attr3},</if>
<if test="attr4 != null">ATTR4 = #{attr4},</if>
<if test="createBy != null">CREATE_BY = #{createBy},</if>
<if test="createTime != null">CREATE_TIME = #{createTime},</if>
<if test="updateBy != null">UPDATE_BY = #{updateBy},</if>
<if test="updateTime != null">UPDATE_TIME = #{updateTime},</if>
</trim>
where CT_MATERIAL_ID = #{ctMaterialId}
</update>
<delete id="deleteUcmCtMaterialByCtMaterialId" parameterType="Long">
delete
from UCM_CT_MATERIAL
where CT_MATERIAL_ID = #{ctMaterialId}
</delete>
<delete id="deleteUcmCtMaterialByCtMaterialIds" parameterType="String">
delete from UCM_CT_MATERIAL where CT_MATERIAL_ID in
<foreach item="ctMaterialId" collection="array" open="(" separator="," close=")">
#{ctMaterialId}
</foreach>
</delete>
</mapper>