fix:系统编码做唯一校验

This commit is contained in:
zhangxuanming 2024-12-31 11:43:46 +08:00
parent 46121c05b6
commit 1f9350abc2
23 changed files with 137 additions and 4 deletions

View File

@ -97,6 +97,9 @@ public class CalPlanController extends BaseController
@PostMapping
public AjaxResult add(@RequestBody CalPlan calPlan)
{
if(UserConstants.NOT_UNIQUE.equals(calPlanService.checkPlanCodeUnique(calPlan))){
return AjaxResult.error("编号已存在!");
}
int ret = calPlanService.insertCalPlan(calPlan);
//根据选择的轮班方式生成默认的班次
calShiftService.addDefaultShift(calPlan.getPlanId(),calPlan.getShiftType());

View File

@ -3,6 +3,7 @@ package com.ktg.mes.cal.controller;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.ktg.common.constant.UserConstants;
import com.ktg.mes.cal.service.ICalTeamMemberService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
@ -92,6 +93,9 @@ public class CalTeamController extends BaseController
@PostMapping
public AjaxResult add(@RequestBody CalTeam calTeam)
{
if(UserConstants.NOT_UNIQUE.equals(calTeamService.checkTeamCodeUnique(calTeam))){
return AjaxResult.error("编号已存在!");
}
return toAjax(calTeamService.insertCalTeam(calTeam));
}
@ -103,6 +107,9 @@ public class CalTeamController extends BaseController
@PutMapping
public AjaxResult edit(@RequestBody CalTeam calTeam)
{
if(UserConstants.NOT_UNIQUE.equals(calTeamService.checkTeamCodeUnique(calTeam))){
return AjaxResult.error("编号已存在!");
}
return toAjax(calTeamService.updateCalTeam(calTeam));
}

View File

@ -62,4 +62,6 @@ public interface CalPlanMapper
* @return 结果
*/
public int deleteCalPlanByPlanIds(Long[] planIds);
CalPlan checkPlanCodeUnique(CalPlan calPlan);
}

View File

@ -58,4 +58,6 @@ public interface CalTeamMapper
* @return 结果
*/
public int deleteCalTeamByTeamIds(Long[] teamIds);
CalTeam checkTeamCodeUnique(CalTeam calTeam);
}

View File

@ -58,4 +58,11 @@ public interface ICalPlanService
* @return 结果
*/
public int deleteCalPlanByPlanId(Long planId);
/**
* 校验编码是否唯一
* @param calPlan
* @return
*/
String checkPlanCodeUnique(CalPlan calPlan);
}

View File

@ -58,4 +58,11 @@ public interface ICalTeamService
* @return 结果
*/
public int deleteCalTeamByTeamId(Long teamId);
/**
* 校验编码是否唯一
* @param calTeam
* @return
*/
String checkTeamCodeUnique(CalTeam calTeam);
}

View File

@ -1,7 +1,10 @@
package com.ktg.mes.cal.service.impl;
import java.util.List;
import com.ktg.common.constant.UserConstants;
import com.ktg.common.utils.DateUtils;
import com.ktg.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ktg.mes.cal.mapper.CalPlanMapper;
@ -93,4 +96,14 @@ public class CalPlanServiceImpl implements ICalPlanService
{
return calPlanMapper.deleteCalPlanByPlanId(planId);
}
@Override
public String checkPlanCodeUnique(CalPlan calPlan) {
CalPlan plan = calPlanMapper.checkPlanCodeUnique(calPlan);
Long planId = calPlan.getPlanId() == null ? -1L : calPlan.getPlanId();
if (StringUtils.isNotNull(plan) && plan.getPlanId().longValue() != planId.longValue()) {
return UserConstants.NOT_UNIQUE;
}
return UserConstants.UNIQUE;
}
}

View File

@ -1,7 +1,10 @@
package com.ktg.mes.cal.service.impl;
import java.util.List;
import com.ktg.common.constant.UserConstants;
import com.ktg.common.utils.DateUtils;
import com.ktg.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ktg.mes.cal.mapper.CalTeamMapper;
@ -93,4 +96,14 @@ public class CalTeamServiceImpl implements ICalTeamService
{
return calTeamMapper.deleteCalTeamByTeamId(teamId);
}
@Override
public String checkTeamCodeUnique(CalTeam calTeam) {
CalTeam team = calTeamMapper.checkTeamCodeUnique(calTeam);
Long teamId = calTeam.getTeamId() == null ? -1L : calTeam.getTeamId();
if (StringUtils.isNotNull(team) && team.getTeamId().longValue() != teamId.longValue()) {
return UserConstants.NOT_UNIQUE;
}
return UserConstants.UNIQUE;
}
}

View File

@ -91,6 +91,9 @@ public class DvCheckPlanController extends BaseController
@PostMapping
public AjaxResult add(@RequestBody DvCheckPlan dvCheckPlan)
{
if(UserConstants.NOT_UNIQUE.equals(dvCheckPlanService.checkPlanCodeUnique(dvCheckPlan))){
return AjaxResult.error("编号已存在!");
}
return toAjax(dvCheckPlanService.insertDvCheckPlan(dvCheckPlan));
}
@ -102,6 +105,9 @@ public class DvCheckPlanController extends BaseController
@PutMapping
public AjaxResult edit(@RequestBody DvCheckPlan dvCheckPlan)
{
if(UserConstants.NOT_UNIQUE.equals(dvCheckPlanService.checkPlanCodeUnique(dvCheckPlan))){
return AjaxResult.error("编号已存在!");
}
if(UserConstants.ORDER_STATUS_FINISHED.equals(dvCheckPlan.getStatus())){
DvCheckMachinery para1 = new DvCheckMachinery();
para1.setPlanId(dvCheckPlan.getPlanId());

View File

@ -78,6 +78,9 @@ public class DvMachineryController extends BaseController
@PostMapping
public AjaxResult add(@RequestBody DvMachinery dvMachinery)
{
if(UserConstants.NOT_UNIQUE.equals(dvMachineryService.checkRecptCodeUnique(dvMachinery))){
return AjaxResult.error("编号已存在!");
}
return dvMachineryService.insertDvMachinery(dvMachinery);
}
@ -89,6 +92,9 @@ public class DvMachineryController extends BaseController
@PutMapping
public AjaxResult edit(@RequestBody DvMachinery dvMachinery)
{
if(UserConstants.NOT_UNIQUE.equals(dvMachineryService.checkRecptCodeUnique(dvMachinery))){
return AjaxResult.error("编号已存在!");
}
return dvMachineryService.updateDvMachinery(dvMachinery);
}

View File

@ -68,4 +68,5 @@ public interface DvMachineryMapper
*/
public int deleteDvMachineryByMachineryIds(Long[] machineryIds);
DvMachinery checkRecptCodeUnique(DvMachinery dvMachinery);
}

View File

@ -71,4 +71,10 @@ public interface IDvMachineryService
*/
public String importMachinery(List<DvMachinery> machineryList, Boolean isUpdateSupport, String operName);
/**
* 查询编码是否唯一
* @param dvMachinery
* @return
*/
String checkRecptCodeUnique(DvMachinery dvMachinery);
}

View File

@ -51,7 +51,7 @@ public class DvCheckPlanServiceImpl implements IDvCheckPlanService
public String checkPlanCodeUnique(DvCheckPlan dvCheckPlan) {
DvCheckPlan plan = dvCheckPlanMapper.checkPlanCodeUnique(dvCheckPlan);
Long planId = dvCheckPlan.getPlanId()==null?-1L:dvCheckPlan.getPlanId();
if(StringUtils.isNotNull(plan) && plan.getPlanId().longValue()==planId.longValue()){
if(StringUtils.isNotNull(plan) && plan.getPlanId().longValue()!=planId.longValue()){
return UserConstants.NOT_UNIQUE;
}
return UserConstants.UNIQUE;

View File

@ -4,6 +4,7 @@ import cn.hutool.core.util.ObjectUtil;
import com.ktg.common.constant.UserConstants;
import com.ktg.common.core.domain.AjaxResult;
import com.ktg.common.utils.DateUtils;
import com.ktg.common.utils.StringUtils;
import com.ktg.mes.dv.domain.DvMachinery;
import com.ktg.mes.dv.mapper.DvMachineryMapper;
import com.ktg.mes.dv.service.IDvMachineryService;
@ -165,5 +166,13 @@ public class DvMachineryServiceImpl implements IDvMachineryService
return String.format("操作用户:%s导入完成成功 %d 条,失败 %d 条。", operName, successCount, failureCount);
}
@Override
public String checkRecptCodeUnique(DvMachinery dvMachinery) {
DvMachinery machinery = dvMachineryMapper.checkRecptCodeUnique(dvMachinery);
Long machineryId = dvMachinery.getMachineryId() == null ? -1L : dvMachinery.getMachineryId();
if (StringUtils.isNotNull(machinery) && machinery.getMachineryId().longValue() != machineryId.longValue()) {
return UserConstants.NOT_UNIQUE;
}
return UserConstants.UNIQUE;
}
}

View File

@ -87,6 +87,9 @@ public class ProCardController extends BaseController
@PostMapping
public AjaxResult add(@RequestBody ProCard proCard)
{
if(UserConstants.NOT_UNIQUE.equals(proCardService.checkCardCodeUnique(proCard))){
return AjaxResult.error("编号已存在!");
}
int ret = proCardService.insertProCard(proCard);
wmBarCodeUtil.generateBarCode(UserConstants.BARCODE_TYPE_PROCARD,proCard.getCardId(),proCard.getCardCode(),"");
return toAjax(ret);
@ -100,6 +103,9 @@ public class ProCardController extends BaseController
@PutMapping
public AjaxResult edit(@RequestBody ProCard proCard)
{
if(UserConstants.NOT_UNIQUE.equals(proCardService.checkCardCodeUnique(proCard))){
return AjaxResult.error("编号已存在!");
}
return toAjax(proCardService.updateProCard(proCard));
}

View File

@ -132,6 +132,9 @@ public class ProWorkorderController extends BaseController
@PutMapping
public AjaxResult edit(@RequestBody ProWorkorder proWorkorder)
{
if(UserConstants.NOT_UNIQUE.equals(proWorkorderService.checkWorkorderCodeUnique(proWorkorder))){
return AjaxResult.error("生产工单编号已存在!");
}
ProWorkorder workorder = proWorkorderService.selectProWorkorderByWorkorderId(proWorkorder.getWorkorderId());
int ret =proWorkorderService.updateProWorkorder(proWorkorder);
//如果是产品和数量发生变化则需要重新生成BOM组成

View File

@ -61,4 +61,6 @@ public interface ProCardMapper
* @return 结果
*/
public int deleteProCardByCardIds(Long[] cardIds);
ProCard checkCardCodeUnique(ProCard proCard);
}

View File

@ -65,4 +65,11 @@ public interface IProCardService
* @return 结果
*/
public int deleteProCardByCardId(Long cardId);
/**
* 校验编码是否唯一
* @param proCard
* @return
*/
String checkCardCodeUnique(ProCard proCard);
}

View File

@ -1,7 +1,10 @@
package com.ktg.mes.pro.service.impl;
import java.util.List;
import com.ktg.common.constant.UserConstants;
import com.ktg.common.utils.DateUtils;
import com.ktg.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ktg.mes.pro.mapper.ProCardMapper;
@ -103,4 +106,14 @@ public class ProCardServiceImpl implements IProCardService
{
return proCardMapper.deleteProCardByCardId(cardId);
}
@Override
public String checkCardCodeUnique(ProCard proCard) {
ProCard card = proCardMapper.checkCardCodeUnique(proCard);
Long cardId = proCard.getCardId() == null ? -1L : proCard.getCardId();
if (StringUtils.isNotNull(card) && card.getCardId().longValue() != cardId.longValue()) {
return UserConstants.NOT_UNIQUE;
}
return UserConstants.UNIQUE;
}
}

View File

@ -50,7 +50,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectCalPlanVo"/>
where plan_id = #{planId}
</select>
<select id="checkPlanCodeUnique" resultType="com.ktg.mes.cal.domain.CalPlan" resultMap="CalPlanResult">
<include refid="selectCalPlanVo"/>
where plan_code = #{planCode}
limit 1
</select>
<insert id="insertCalPlan" parameterType="CalPlan" useGeneratedKeys="true" keyProperty="planId">
insert into cal_plan
<trim prefix="(" suffix=")" suffixOverrides=",">

View File

@ -37,7 +37,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectCalTeamVo"/>
where team_id = #{teamId}
</select>
<select id="checkTeamCodeUnique" resultType="com.ktg.mes.cal.domain.CalTeam" resultMap="CalTeamResult">
<include refid="selectCalTeamVo"/>
where team_code = #{teamCode}
limit 1
</select>
<insert id="insertCalTeam" parameterType="CalTeam" useGeneratedKeys="true" keyProperty="teamId">
insert into cal_team
<trim prefix="(" suffix=")" suffixOverrides=",">

View File

@ -60,6 +60,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectDvMachineryVo"/>
where machinery_code= #{machineryCode}
</select>
<select id="checkRecptCodeUnique" resultType="com.ktg.mes.dv.domain.DvMachinery" resultMap="DvMachineryResult">
<include refid="selectDvMachineryVo"/>
where machinery_code = #{machineryCode}
limit 1
</select>
<insert id="insertDvMachinery" parameterType="DvMachinery" useGeneratedKeys="true" keyProperty="machineryId">
insert into dv_machinery

View File

@ -74,6 +74,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and pcp.workstation_id = #{workstationId}
order by pcp.input_time desc
</select>
<select id="checkCardCodeUnique" resultType="com.ktg.mes.pro.domain.ProCard" resultMap="ProCardResult">
<include refid="selectProCardVo"/>
where card_code = #{cardCode}
limit 1
</select>
<insert id="insertProCard" parameterType="ProCard" useGeneratedKeys="true" keyProperty="cardId">