Merge remote-tracking branch 'origin/master'

master
zhaoxiaolin 6 months ago
commit 33beab5b92

@ -4,6 +4,7 @@ import java.util.List;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.dynamic.datasource.annotation.DS;
import com.op.common.security.utils.SecurityUtils;
import com.op.system.api.domain.SysDictType; import com.op.system.api.domain.SysDictType;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@ -75,6 +76,9 @@ public class MesBoxController extends BaseController {
@Log(title = "箱体类型", businessType = BusinessType.INSERT) @Log(title = "箱体类型", businessType = BusinessType.INSERT)
@PostMapping @PostMapping
public AjaxResult add(@RequestBody MesBox mesBox) { public AjaxResult add(@RequestBody MesBox mesBox) {
if (!mesBoxService.checkBoxTypeUnique(mesBox)) {
return error("新增箱型'" + mesBox.getBoxName() + "'失败,箱体类型已存在");
}
return toAjax(mesBoxService.insertMesBox(mesBox)); return toAjax(mesBoxService.insertMesBox(mesBox));
} }
@ -85,6 +89,9 @@ public class MesBoxController extends BaseController {
@Log(title = "箱体类型", businessType = BusinessType.UPDATE) @Log(title = "箱体类型", businessType = BusinessType.UPDATE)
@PutMapping @PutMapping
public AjaxResult edit(@RequestBody MesBox mesBox) { public AjaxResult edit(@RequestBody MesBox mesBox) {
if (!mesBoxService.checkBoxTypeUnique(mesBox)) {
return error("修改箱型'" + mesBox.getBoxName() + "'失败,箱体类型已存在");
}
return toAjax(mesBoxService.updateMesBox(mesBox)); return toAjax(mesBoxService.updateMesBox(mesBox));
} }

@ -60,4 +60,8 @@ public interface MesBoxMapper {
public int deleteMesBoxByBoxIds(Long[] boxIds); public int deleteMesBoxByBoxIds(Long[] boxIds);
List<MesBox> selectDictTypeAll(); List<MesBox> selectDictTypeAll();
MesBox checkBoxTypeUnique(String boxType);
int countBoxDataByType(String boxType);
} }

@ -60,4 +60,6 @@ public interface IMesBoxService {
public int deleteMesBoxByBoxId(Long boxId); public int deleteMesBoxByBoxId(Long boxId);
List<MesBox> selectDictTypeAll(); List<MesBox> selectDictTypeAll();
boolean checkBoxTypeUnique(MesBox mesBox);
} }

@ -3,8 +3,13 @@ package com.op.mes.service.impl;
import java.util.List; import java.util.List;
import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.dynamic.datasource.annotation.DS;
import com.op.common.core.constant.UserConstants;
import com.op.common.core.exception.ServiceException;
import com.op.common.core.utils.DateUtils; import com.op.common.core.utils.DateUtils;
import com.op.common.core.utils.StringUtils;
import com.op.common.security.utils.DictUtils;
import com.op.common.security.utils.SecurityUtils; import com.op.common.security.utils.SecurityUtils;
import com.op.system.api.domain.SysDictType;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.op.mes.mapper.MesBoxMapper; import com.op.mes.mapper.MesBoxMapper;
@ -55,7 +60,7 @@ public class MesBoxServiceImpl implements IMesBoxService {
@Override @Override
@DS("#header.poolName") @DS("#header.poolName")
public int insertMesBox(MesBox mesBox) { public int insertMesBox(MesBox mesBox) {
mesBox.setUpdateBy(SecurityUtils.getUsername()); mesBox.setCreateBy(SecurityUtils.getUsername());
mesBox.setCreateTime(DateUtils.getNowDate()); mesBox.setCreateTime(DateUtils.getNowDate());
return mesBoxMapper.insertMesBox(mesBox); return mesBoxMapper.insertMesBox(mesBox);
} }
@ -83,7 +88,16 @@ public class MesBoxServiceImpl implements IMesBoxService {
@Override @Override
@DS("#header.poolName") @DS("#header.poolName")
public int deleteMesBoxByBoxIds(Long[] boxIds) { public int deleteMesBoxByBoxIds(Long[] boxIds) {
return mesBoxMapper.deleteMesBoxByBoxIds(boxIds); int n = 0;
for (Long boxId : boxIds) {
MesBox boxType = selectMesBoxByBoxId(boxId);
if (mesBoxMapper.countBoxDataByType(boxType.getBoxType()) > 0) {
throw new ServiceException(String.format("%1$s已分配,不能删除", boxType.getBoxName()));
}
n += mesBoxMapper.deleteMesBoxByBoxIds(boxIds);
}
return n;
} }
/** /**
@ -103,4 +117,14 @@ public class MesBoxServiceImpl implements IMesBoxService {
public List<MesBox> selectDictTypeAll() { public List<MesBox> selectDictTypeAll() {
return mesBoxMapper.selectDictTypeAll(); return mesBoxMapper.selectDictTypeAll();
} }
@Override
public boolean checkBoxTypeUnique(MesBox mesBox) {
Long boxId = StringUtils.isNull(mesBox.getBoxId()) ? -1L : mesBox.getBoxId();
MesBox boxType = mesBoxMapper.checkBoxTypeUnique(mesBox.getBoxType());
if (StringUtils.isNotNull(boxType) && boxType.getBoxId().longValue() != boxId.longValue()) {
return UserConstants.NOT_UNIQUE;
}
return UserConstants.UNIQUE;
}
} }

@ -33,12 +33,13 @@
and status = #{status} and status = #{status}
</if> </if>
</where> </where>
where del_flag = '0'
</select> </select>
<select id="selectMesBoxByBoxId" parameterType="Long" <select id="selectMesBoxByBoxId" parameterType="Long"
resultMap="MesBoxResult"> resultMap="MesBoxResult">
<include refid="selectMesBoxVo"/> <include refid="selectMesBoxVo"/>
where box_id = #{boxId} where box_id = #{boxId} and del_flag = '0'
</select> </select>
<insert id="insertMesBox" parameterType="MesBox"> <insert id="insertMesBox" parameterType="MesBox">
@ -120,14 +121,24 @@
<include refid="selectMesBoxVo"/> <include refid="selectMesBoxVo"/>
</select> </select>
<select id="countBoxDataByType" resultType="Integer">
select count(1) from mes_box_detail where box_type=#{boxType}
</select>
<delete id="deleteMesBoxByBoxId" parameterType="Long"> <delete id="deleteMesBoxByBoxId" parameterType="Long">
delete from mes_box where box_id = #{boxId} update mes_box set del_flag = '1' where box_id = #{boxId}
</delete> </delete>
<delete id="deleteMesBoxByBoxIds" parameterType="String"> <delete id="deleteMesBoxByBoxIds" parameterType="String">
delete from mes_box where box_id in update mes_box set del_flag = '1' where box_id in
<foreach item="boxId" collection="array" open="(" separator="," close=")"> <foreach item="boxId" collection="array" open="(" separator="," close=")">
#{boxId} #{boxId}
</foreach> </foreach>
</delete> </delete>
<select id="checkBoxTypeUnique" parameterType="String" resultMap="MesBoxResult">
select top 1 box_id, box_name, box_type, status, create_by, create_time, remark
from mes_box
where box_type = #{boxType}
</select>
</mapper> </mapper>

Loading…
Cancel
Save