diff --git a/ktg-mes/src/main/java/com/ktg/mes/md/mapper/UcmCtMaterialMapper2.java b/ktg-mes/src/main/java/com/ktg/mes/md/mapper/UcmCtMaterialMapper2.java new file mode 100644 index 0000000..980b511 --- /dev/null +++ b/ktg-mes/src/main/java/com/ktg/mes/md/mapper/UcmCtMaterialMapper2.java @@ -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 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); +} diff --git a/ktg-mes/src/main/java/com/ktg/mes/wm/controller/UcmCtBaseController.java b/ktg-mes/src/main/java/com/ktg/mes/wm/controller/UcmCtBaseController.java index 8bcb618..edefdd3 100644 --- a/ktg-mes/src/main/java/com/ktg/mes/wm/controller/UcmCtBaseController.java +++ b/ktg-mes/src/main/java/com/ktg/mes/wm/controller/UcmCtBaseController.java @@ -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 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 list = ucmCtBaseService.selectUcmCtBaseList(ucmCtBase); ExcelUtil util = new ExcelUtil(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)); + } } diff --git a/ktg-mes/src/main/java/com/ktg/mes/wm/service/IUcmCtBaseService.java b/ktg-mes/src/main/java/com/ktg/mes/wm/service/IUcmCtBaseService.java index 7b0d6a7..c1b56ee 100644 --- a/ktg-mes/src/main/java/com/ktg/mes/wm/service/IUcmCtBaseService.java +++ b/ktg-mes/src/main/java/com/ktg/mes/wm/service/IUcmCtBaseService.java @@ -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); } diff --git a/ktg-mes/src/main/java/com/ktg/mes/wm/service/impl/UcmCtBaseServiceImpl.java b/ktg-mes/src/main/java/com/ktg/mes/wm/service/impl/UcmCtBaseServiceImpl.java index 6ef4da1..20ae27e 100644 --- a/ktg-mes/src/main/java/com/ktg/mes/wm/service/impl/UcmCtBaseServiceImpl.java +++ b/ktg-mes/src/main/java/com/ktg/mes/wm/service/impl/UcmCtBaseServiceImpl.java @@ -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 selectUcmCtBaseList(UcmCtBase ucmCtBase) - { + public List 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 ucmCtBaseList = ucmCtBaseMapper.selectUcmCtBaseList(ucmCtBaseQuery); + if (ucmCtBaseList.isEmpty()) + throw new RuntimeException("绑定失败,该料箱不存在"); + + BaseKnife baseKnifeQuery = new BaseKnife(); + baseKnifeQuery.setRfid(itemCode); + List 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 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 ucmCtBaseList = ucmCtBaseMapper.selectUcmCtBaseList(ucmCtBaseQuery); + if (ucmCtBaseList.isEmpty()) + throw new RuntimeException("解绑失败,该料箱不存在"); + + BaseKnife baseKnifeQuery = new BaseKnife(); + baseKnifeQuery.setRfid(itemCode); + List 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 ucmCtMaterialList = ucmCtMaterialMapper2.selectUcmCtMaterialList(ucmCtMaterialQuery); + if (ucmCtMaterialList.isEmpty()) + throw new RuntimeException("解绑失败,该物料并未绑定该料箱"); + + ucmCtMaterialList.forEach(item -> { + ucmCtMaterialMapper2.deleteUcmCtMaterialByCtMaterialId(item.getCtMaterialId()); + }); + + return ucmCtMaterialList.size(); + } } diff --git a/ktg-mes/src/main/resources/mapper/md/UcmCtMaterialMapper.xml b/ktg-mes/src/main/resources/mapper/md/UcmCtMaterialMapper.xml new file mode 100644 index 0000000..e91f25a --- /dev/null +++ b/ktg-mes/src/main/resources/mapper/md/UcmCtMaterialMapper.xml @@ -0,0 +1,116 @@ + + + + + + + + + + + + + + + + + + + + + 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 + + + + + + + + insert into UCM_CT_MATERIAL + + CT_BASE_ID, + BASE_KNIFE_ID, + REMARK, + ATTR1, + ATTR2, + ATTR3, + ATTR4, + CREATE_BY, + CREATE_TIME, + UPDATE_BY, + UPDATE_TIME, + + + #{ctBaseId}, + #{baseKnifeId}, + #{remark}, + #{attr1}, + #{attr2}, + #{attr3}, + #{attr4}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + + + + + update UCM_CT_MATERIAL + + CT_BASE_ID = #{ctBaseId}, + BASE_KNIFE_ID = #{baseKnifeId}, + REMARK = #{remark}, + ATTR1 = #{attr1}, + ATTR2 = #{attr2}, + ATTR3 = #{attr3}, + ATTR4 = #{attr4}, + CREATE_BY = #{createBy}, + CREATE_TIME = #{createTime}, + UPDATE_BY = #{updateBy}, + UPDATE_TIME = #{updateTime}, + + where CT_MATERIAL_ID = #{ctMaterialId} + + + + delete + from UCM_CT_MATERIAL + where CT_MATERIAL_ID = #{ctMaterialId} + + + + delete from UCM_CT_MATERIAL where CT_MATERIAL_ID in + + #{ctMaterialId} + + + \ No newline at end of file