装备管理新增修改逻辑优化
This commit is contained in:
		
							parent
							
								
									58ed988693
								
							
						
					
					
						commit
						f35e16dd70
					
				| 
						 | 
				
			
			@ -117,8 +117,8 @@ public class DevInfoController extends BaseController {
 | 
			
		|||
     */
 | 
			
		||||
   // @RequiresPermissions("equip:info:edit")
 | 
			
		||||
    @ApiOperation(value = "修改装备信息")
 | 
			
		||||
    @PutMapping
 | 
			
		||||
    public AjaxResult edit(@RequestBody @NotNull @Valid DevInfo devInfo) {
 | 
			
		||||
    @PostMapping("edit")
 | 
			
		||||
    public AjaxResult edit(@RequestBody @Valid DevInfo devInfo) {
 | 
			
		||||
        return devInfoService.updateDevInfo(devInfo);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -159,7 +159,7 @@ public class DevInfoController extends BaseController {
 | 
			
		|||
    //@RequiresPermissions("equip:info:add")
 | 
			
		||||
    @ApiOperation(value = "新增装备--含附件上传")
 | 
			
		||||
    @PostMapping
 | 
			
		||||
    public AjaxResult add(@RequestBody @NotNull @Valid DevInfo devInfo) {
 | 
			
		||||
    public AjaxResult add(@RequestBody @Valid DevInfo devInfo) {
 | 
			
		||||
        return devInfoService.insertDevInfo(devInfo);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -35,7 +35,7 @@ public interface DevInfoMapper {
 | 
			
		|||
     * @param deviceName 物资名称
 | 
			
		||||
     * @return 条数
 | 
			
		||||
     */
 | 
			
		||||
    Integer getDeviceNameCount(String deviceName);
 | 
			
		||||
    DevInfo getDeviceNameCount(String deviceName);
 | 
			
		||||
 | 
			
		||||
    int insertHotSearch(Long maId);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -165,5 +165,7 @@ public interface DevInfoMapper {
 | 
			
		|||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    DevInfoVo selectCompanyById(String companyId);
 | 
			
		||||
 | 
			
		||||
    String getCodeByMaId(Long maId);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -277,8 +277,10 @@ public class DevInfoServiceImpl implements DevInfoService {
 | 
			
		|||
        if (devInfo == null) {
 | 
			
		||||
            return AjaxResult.error("设备信息不能为空");
 | 
			
		||||
        }
 | 
			
		||||
        String code = "";
 | 
			
		||||
        try {
 | 
			
		||||
            if (devInfo.getMaId() != null) {
 | 
			
		||||
                code = devInfoMapper.getCodeByMaId(devInfo.getMaId());
 | 
			
		||||
                // 更新设备信息--原本草稿相关内容删除
 | 
			
		||||
                int deleted = devInfoMapper.deleteDevInfoByMaId(devInfo.getMaId(), MaStatusEnum.UNDER_RENT.getCode());
 | 
			
		||||
                if (deleted == 0) {
 | 
			
		||||
| 
						 | 
				
			
			@ -298,8 +300,8 @@ public class DevInfoServiceImpl implements DevInfoService {
 | 
			
		|||
            throw new ServiceException("非法参数异常: " + e.getMessage());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Integer deviceNameCount = devInfoMapper.getDeviceNameCount(devInfo.getDeviceName());
 | 
			
		||||
        if (deviceNameCount != null && deviceNameCount > 0) {
 | 
			
		||||
        DevInfo deviceNameCount = devInfoMapper.getDeviceNameCount(devInfo.getDeviceName());
 | 
			
		||||
        if (deviceNameCount != null && deviceNameCount.getMaId() > 0) {
 | 
			
		||||
            return AjaxResult.error("设备名称已存在,请修改后重试!");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -307,7 +309,9 @@ public class DevInfoServiceImpl implements DevInfoService {
 | 
			
		|||
        Long userId = SecurityUtils.getLoginUser().getUserid();
 | 
			
		||||
        //保存用户信息
 | 
			
		||||
        devInfo.setCreator(userId).setMaStatus(ON_HIRE.getCode()).setOwnId(userId);
 | 
			
		||||
        String code = getString();
 | 
			
		||||
        if (org.apache.commons.lang3.StringUtils.isBlank(code)){
 | 
			
		||||
            code = getString();
 | 
			
		||||
        }
 | 
			
		||||
        devInfo.setCode(code);
 | 
			
		||||
        int saveSuccessNum = devInfoMapper.insertDevInfo(devInfo);
 | 
			
		||||
        if (saveSuccessNum == 0) {
 | 
			
		||||
| 
						 | 
				
			
			@ -424,8 +428,8 @@ public class DevInfoServiceImpl implements DevInfoService {
 | 
			
		|||
        if (devInfo.getMaId() == null) {
 | 
			
		||||
            return AjaxResult.error("设备ID为空,请携带设备信息修改");
 | 
			
		||||
        }
 | 
			
		||||
        int deviceId = devInfoMapper.getDeviceNameCount(devInfo.getDeviceName());
 | 
			
		||||
        if (deviceId > 0 && deviceId != devInfo.getMaId()) {
 | 
			
		||||
        DevInfo deviceId = devInfoMapper.getDeviceNameCount(devInfo.getDeviceName());
 | 
			
		||||
        if (deviceId != null && !deviceId.getMaId().equals(devInfo.getMaId())) {
 | 
			
		||||
            return AjaxResult.error("设备名称已存在,请修改后重试!");
 | 
			
		||||
        }
 | 
			
		||||
        return devInfoMapper.updateDevInfo(devInfo) > 0 ? AjaxResult.success("修改成功") : AjaxResult.error("修改失败");
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -406,11 +406,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 | 
			
		|||
        where ma_id = #{maId}
 | 
			
		||||
    </select>
 | 
			
		||||
 | 
			
		||||
    <select id="getDeviceNameCount" resultType="Integer">
 | 
			
		||||
        select ma_id from ma_dev_info
 | 
			
		||||
        where device_name = #{deviceName,jdbcType=VARCHAR} and is_active = '1'
 | 
			
		||||
    </select>
 | 
			
		||||
 | 
			
		||||
    <insert id="insertHotSearch">
 | 
			
		||||
        INSERT INTO ma_hot_search (ma_id, search_num, create_time)
 | 
			
		||||
        VALUES (#{maId}, 1, now())
 | 
			
		||||
| 
						 | 
				
			
			@ -676,5 +671,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 | 
			
		|||
        from bm_company_info
 | 
			
		||||
        where company_id = #{companyId}
 | 
			
		||||
    </select>
 | 
			
		||||
    <select id="getCodeByMaId" resultType="java.lang.String">
 | 
			
		||||
        select code from ma_dev_info where ma_id = #{maId}
 | 
			
		||||
    </select>
 | 
			
		||||
    <select id="getDeviceNameCount" resultType="com.bonus.material.device.domain.DevInfo">
 | 
			
		||||
        select ma_id from ma_dev_info
 | 
			
		||||
        where device_name = #{deviceName,jdbcType=VARCHAR} and is_active = '1'
 | 
			
		||||
    </select>
 | 
			
		||||
 | 
			
		||||
</mapper>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue