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;
@ -36,11 +37,11 @@ public class MesBoxController extends BaseController {
@Autowired @Autowired
private IMesBoxService mesBoxService; private IMesBoxService mesBoxService;
/** /**
* *
*/ */
@RequiresPermissions("mes:mesBox:list") @RequiresPermissions("mes:mesBox:list")
@GetMapping("/list") @GetMapping("/list")
public TableDataInfo list(MesBox mesBox) { public TableDataInfo list(MesBox mesBox) {
startPage(); startPage();
List<MesBox> list = mesBoxService.selectMesBoxList(mesBox); List<MesBox> list = mesBoxService.selectMesBoxList(mesBox);
@ -55,7 +56,7 @@ public class MesBoxController extends BaseController {
@PostMapping("/export") @PostMapping("/export")
public void export(HttpServletResponse response, MesBox mesBox) { public void export(HttpServletResponse response, MesBox mesBox) {
List<MesBox> list = mesBoxService.selectMesBoxList(mesBox); List<MesBox> list = mesBoxService.selectMesBoxList(mesBox);
ExcelUtil<MesBox> util = new ExcelUtil<MesBox>(MesBox. class); ExcelUtil<MesBox> util = new ExcelUtil<MesBox>(MesBox.class);
util.exportExcel(response, list, "箱体类型数据"); util.exportExcel(response, list, "箱体类型数据");
} }
@ -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">
@ -88,30 +89,30 @@
<update id="updateMesBox" parameterType="MesBox"> <update id="updateMesBox" parameterType="MesBox">
update mes_box update mes_box
<trim prefix="SET" suffixOverrides=","> <trim prefix="SET" suffixOverrides=",">
<if test="boxName != null">box_name = <if test="boxName != null">box_name =
#{boxName}, #{boxName},
</if> </if>
<if test="boxType != null">box_type = <if test="boxType != null">box_type =
#{boxType}, #{boxType},
</if> </if>
<if test="status != null">status = <if test="status != null">status =
#{status}, #{status},
</if> </if>
<if test="createBy != null">create_by = <if test="createBy != null">create_by =
#{createBy}, #{createBy},
</if> </if>
<if test="createTime != null">create_time = <if test="createTime != null">create_time =
#{createTime}, #{createTime},
</if> </if>
<if test="updateBy != null">update_by = <if test="updateBy != null">update_by =
#{updateBy}, #{updateBy},
</if> </if>
<if test="updateTime != null">update_time = <if test="updateTime != null">update_time =
#{updateTime}, #{updateTime},
</if> </if>
<if test="remark != null">remark = <if test="remark != null">remark =
#{remark}, #{remark},
</if> </if>
</trim> </trim>
where box_id = #{boxId} where box_id = #{boxId}
</update> </update>
@ -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