设备库存处理和装备code改成自动生成
This commit is contained in:
		
							parent
							
								
									d60dba621b
								
							
						
					
					
						commit
						fc30422185
					
				| 
						 | 
				
			
			@ -9,6 +9,7 @@ import com.bonus.material.device.domain.vo.DevInfoVo;
 | 
			
		|||
import com.bonus.material.device.domain.vo.LeaseVo;
 | 
			
		||||
import org.apache.ibatis.annotations.Param;
 | 
			
		||||
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
| 
						 | 
				
			
			@ -153,5 +154,7 @@ public interface DevInfoMapper {
 | 
			
		|||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    List<LeaseVo> getLeaseList(Long maId);
 | 
			
		||||
 | 
			
		||||
    String selectTaskNumByMonth(@Param("date") Date nowDate);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,6 +5,7 @@ import com.bonus.common.biz.constant.MaterialConstants;
 | 
			
		|||
import com.bonus.common.biz.domain.*;
 | 
			
		||||
import com.bonus.common.biz.enums.MaStatusEnum;
 | 
			
		||||
import com.bonus.common.core.exception.ServiceException;
 | 
			
		||||
import com.bonus.common.core.utils.DateUtils;
 | 
			
		||||
import com.bonus.common.core.utils.StringUtils;
 | 
			
		||||
import com.bonus.common.core.utils.bean.BeanUtils;
 | 
			
		||||
import com.bonus.common.core.web.domain.AjaxResult;
 | 
			
		||||
| 
						 | 
				
			
			@ -28,6 +29,7 @@ import org.springframework.transaction.annotation.Transactional;
 | 
			
		|||
import org.springframework.util.CollectionUtils;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Resource;
 | 
			
		||||
import java.text.SimpleDateFormat;
 | 
			
		||||
import java.util.*;
 | 
			
		||||
import java.util.stream.Collectors;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -290,6 +292,8 @@ public class DevInfoServiceImpl implements DevInfoService {
 | 
			
		|||
        Long userId = SecurityUtils.getLoginUser().getUserid();
 | 
			
		||||
        //保存用户信息
 | 
			
		||||
        devInfo.setCreator(userId).setMaStatus(ON_HIRE.getCode()).setOwnId(userId);
 | 
			
		||||
        String code = getString();
 | 
			
		||||
        devInfo.setCode(code);
 | 
			
		||||
        int saveSuccessNum = devInfoMapper.insertDevInfo(devInfo);
 | 
			
		||||
        if (saveSuccessNum == 0) {
 | 
			
		||||
            return AjaxResult.error("设备信息SQL保存失败,请修改后重试");
 | 
			
		||||
| 
						 | 
				
			
			@ -580,4 +584,23 @@ public class DevInfoServiceImpl implements DevInfoService {
 | 
			
		|||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private String getString() {
 | 
			
		||||
        //根据前台传过来的数据,生成需求编号
 | 
			
		||||
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
 | 
			
		||||
        Date nowDate = DateUtils.getNowDate();
 | 
			
		||||
        String format = dateFormat.format(nowDate);
 | 
			
		||||
        String taskNum = devInfoMapper.selectTaskNumByMonth(nowDate);
 | 
			
		||||
        if (StringUtils.isNotBlank(taskNum)) {
 | 
			
		||||
            // 将字符串转换为整数
 | 
			
		||||
            int num = Integer.parseInt(taskNum);
 | 
			
		||||
            // 执行加一操作
 | 
			
		||||
            num++;
 | 
			
		||||
            // 将结果转换回字符串格式,并确保结果是4位数,不足4位则在前面补0
 | 
			
		||||
            taskNum = String.format("%04d", num);
 | 
			
		||||
        } else {
 | 
			
		||||
            taskNum = "0001";
 | 
			
		||||
        }
 | 
			
		||||
        return format + "-" + taskNum;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -84,4 +84,7 @@ public class OrderDetailDto {
 | 
			
		|||
 | 
			
		||||
    @ApiModelProperty(value = "租赁结束时间")
 | 
			
		||||
    private String rentOverTime;
 | 
			
		||||
 | 
			
		||||
    @ApiModelProperty(value = "设备状态")
 | 
			
		||||
    private String maStatus;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -32,9 +32,14 @@ public class OrderServiceImpl implements OrderService {
 | 
			
		|||
        for (OrderDetailDto orderDetailDto : orderDetailDtos) {
 | 
			
		||||
            // 如果是数量设备 ,改库存
 | 
			
		||||
            if ("1".equals(orderDetailDto.getManageType())) {
 | 
			
		||||
                // 先查询库存是否足够
 | 
			
		||||
                // 再查询库存是否足够
 | 
			
		||||
                DevInfo devInfo = orderMapper.getdeviceCount(orderDetailDto);
 | 
			
		||||
                if (devInfo.getDeviceCount() < orderDetailDto.getNum()) {
 | 
			
		||||
                if (devInfo.getDeviceCount() == 0) {
 | 
			
		||||
                    // 查询库存是否为0,是的话让它下架
 | 
			
		||||
                    orderDetailDto.setMaStatus("1");
 | 
			
		||||
                    orderMapper.updateDeviceStatus(orderDetailDto);
 | 
			
		||||
                    throw new RuntimeException(devInfo.getDeviceName() + "库存不足");
 | 
			
		||||
                }else if (devInfo.getDeviceCount() < orderDetailDto.getNum()) {
 | 
			
		||||
                    throw new RuntimeException(devInfo.getDeviceName() + "库存不足");
 | 
			
		||||
                } else {
 | 
			
		||||
                    // 改库存
 | 
			
		||||
| 
						 | 
				
			
			@ -42,6 +47,7 @@ public class OrderServiceImpl implements OrderService {
 | 
			
		|||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                //如果是编码设备,改设备状态为在租
 | 
			
		||||
                orderDetailDto.setMaStatus("3");
 | 
			
		||||
                orderMapper.updateDeviceStatus(orderDetailDto);
 | 
			
		||||
            }
 | 
			
		||||
            // 更改购物车状态为已下单
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -672,5 +672,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 | 
			
		|||
        GROUP BY
 | 
			
		||||
        m.own_co
 | 
			
		||||
    </select>
 | 
			
		||||
    <select id="selectTaskNumByMonth" resultType="java.lang.String">
 | 
			
		||||
        SELECT SUBSTRING(code, - 4) as code
 | 
			
		||||
        FROM ma_dev_info
 | 
			
		||||
        WHERE DATE_FORMAT(create_time, '%y%m') = DATE_FORMAT(#{date}, '%y%m')
 | 
			
		||||
        ORDER BY create_time DESC LIMIT 1
 | 
			
		||||
    </select>
 | 
			
		||||
 | 
			
		||||
</mapper>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -34,7 +34,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 | 
			
		|||
             #{updateTime})
 | 
			
		||||
    </insert>
 | 
			
		||||
    <update id="updateDeviceStatus">
 | 
			
		||||
        update ma_dev_info set ma_status = 3  where ma_id = #{maId} and is_active = 1
 | 
			
		||||
        update ma_dev_info set ma_status = #{maStatus}  where ma_id = #{maId} and is_active = 1
 | 
			
		||||
    </update>
 | 
			
		||||
    <update id="updateMaStatus">
 | 
			
		||||
        update book_car_detail set order_status = 1  where id = #{id}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue