Commit e018cc42 by zhanghj

V1.2.0--增加公用的减少和增加库存方法

git-svn-id: svn://192.168.3.233/frms/code/car-service/trunk/car-service@22013 aeb6102e-e053-11e5-9fec-f9ebc45caf4b
1 parent b2d8838d
......@@ -73,8 +73,8 @@ public enum ResultCodeEnum {
/**
* 库存相关
*/
DEVICE_REPERTORY_NOT_EXIST(5200, "用户没有库存,不能给下属技工发货"),
DEVICE_REPERTORY_NOT_ENOUGH(5201, "用户库存不足,不能给下属技工发货")
DEVICE_REPERTORY_NOT_EXIST(5200, "用户没有库存"),
DEVICE_REPERTORY_NOT_ENOUGH(5201, "用户库存不足")
;
/**
......
package com.glsx.ordercenter.service;
import com.glsx.common.constants.ResultObject;
import com.glsx.ordercenter.dto.DeviceRepertoryReq;
import com.glsx.ordercenter.dto.MechanicRepertoryReq;
import com.glsx.ordercenter.pojo.SysDeviceRepertory;
......@@ -95,4 +96,29 @@ public interface DeviceRepertoryService {
*/
List<MechanicRepertoryReq> getMechanicRepertoryList(Integer sortType, String deviceType, String name, Integer userId);
/**
*
* @author zhanghj
* @Title: reduceDeviceRepertory
* @Description: TODO 减少用户的库存
* @param userId
* @param deviceType
* @param deviceAmount
* @return
* ResultObject
*
*/
ResultObject reduceDeviceRepertory(Integer userId, String deviceType, Integer deviceAmount);
/**
*
* @author zhanghj
* @Title: addDeviceRepertory
* @Description: TODO 增加用户库存
* @param userId
* @param deviceType
* @param deviceAmount
* void
*
*/
int addDeviceRepertory(Integer userId, String deviceType, Integer deviceAmount);
}
package com.glsx.ordercenter.service.impl;
import com.glsx.common.constants.ResultObject;
import com.glsx.common.utils.UserUtils;
import com.glsx.ordercenter.constants.ResultCodeEnum;
import com.glsx.ordercenter.dto.DeviceRepertoryReq;
import com.glsx.ordercenter.dto.MechanicRepertoryReq;
import com.glsx.ordercenter.exception.BusinessException;
import com.glsx.ordercenter.mapper.SysDeviceMapper;
import com.glsx.ordercenter.mapper.SysDeviceRepertoryMapper;
import com.glsx.ordercenter.mapper.SysIndentMapper;
......@@ -14,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -135,4 +139,65 @@ public class DeviceRepertoryServiceImpl implements DeviceRepertoryService {
// TODO Auto-generated method stub
return sysDeviceRepertoryMapper.insertSelective(deviceRepertory);
}
@Override
public ResultObject reduceDeviceRepertory(Integer userId,
String deviceType, Integer deviceAmount) {
// TODO Auto-generated method stub
ResultObject result = null;
SysDeviceRepertory deviceRepertory = new SysDeviceRepertory();
deviceRepertory.setUserId(userId);
deviceRepertory.setDeviceType(deviceType);
SysDeviceRepertory repertory = sysDeviceRepertoryMapper.get(deviceRepertory);
if (repertory == null) {
result = new ResultObject(ResultCodeEnum.DEVICE_REPERTORY_NOT_EXIST.getCode(), ResultCodeEnum.DEVICE_REPERTORY_NOT_EXIST.getMsg());
return result;
}
Integer deviceNum = repertory.getDeviceNum();
if (deviceNum < deviceAmount) {
result = new ResultObject(ResultCodeEnum.DEVICE_REPERTORY_NOT_ENOUGH.getCode(), ResultCodeEnum.DEVICE_REPERTORY_NOT_ENOUGH.getMsg());
return result;
}
Integer totalDeviceNum = deviceNum - deviceAmount;
deviceRepertory.setDeviceNum(totalDeviceNum);
deviceRepertory.setUpdateTime(new Date());
Integer version = repertory.getVersion();
deviceRepertory.setVersion(version);
int n = sysDeviceRepertoryMapper.updateSelective(deviceRepertory);
if (n <= 0) {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), ResultCodeEnum.FAIL.getMsg());
}
return result;
}
@Override
public int addDeviceRepertory(Integer userId, String deviceType,
Integer deviceAmount) {
// TODO Auto-generated method stub
int num = 0;
SysDeviceRepertory deviceRepertory = new SysDeviceRepertory();
deviceRepertory.setUserId(userId);
deviceRepertory.setDeviceType(deviceType);
SysDeviceRepertory repertory = sysDeviceRepertoryMapper.get(deviceRepertory);
if (repertory != null) {
Integer deviceNum = repertory.getDeviceNum();
Integer totalDeviceNum = deviceNum + deviceAmount;
deviceRepertory.setDeviceNum(totalDeviceNum);
deviceRepertory.setUpdateTime(new Date());
Integer version = repertory.getVersion();
deviceRepertory.setVersion(version);
num = sysDeviceRepertoryMapper.updateSelective(deviceRepertory);
if (num <= 0) {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), ResultCodeEnum.FAIL.getMsg());
}
} else {
deviceRepertory.setDeviceNum(deviceAmount);
deviceRepertory.setCreateTime(new Date());
num = sysDeviceRepertoryMapper.insertSelective(deviceRepertory);
if (num <= 0) {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), ResultCodeEnum.FAIL.getMsg());
}
}
return num;
}
}
......@@ -26,7 +26,6 @@ import com.glsx.common.utils.Page;
import com.glsx.common.utils.UserUtils;
import com.glsx.ordercenter.constants.BizConstants;
import com.glsx.ordercenter.constants.IndentStatusEnum;
import com.glsx.ordercenter.constants.OrderActiveStatusEnum;
import com.glsx.ordercenter.constants.ResultCodeEnum;
import com.glsx.ordercenter.dto.Traces;
import com.glsx.ordercenter.dto.TracesVo;
......@@ -521,25 +520,24 @@ public class IndentServiceImpl implements IndentService {
* 若为服务商发货,技工确认收货,则服务商库存减少,技工库存增加
* 若为广联发货,增加接收人库存;添加技工所属服务商库存记录
*/
Integer serviceId;
JSONObject obj = userClient.getMechanicSP(userId);
if (obj != null && obj.getIntValue("code") == ResultCodeEnum.SUCCESS.getCode()) {
serviceId = obj.getInteger("data");
} else {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), ResultCodeEnum.FAIL.getMsg());
}
if (BizConstants.INDENT_SEND_TYPE_GLSX == sendType) {
addDeviceRepertory(userId, deviceType, deviceAmount);
addDeviceRepertory(serviceId,deviceType,0);
deviceRepertoryService.addDeviceRepertory(userId, deviceType, deviceAmount);
} else {
Integer serviceId;
JSONObject obj = userClient.getMechanicSP(userId);
if (obj != null && obj.getIntValue("code") == ResultCodeEnum.SUCCESS.getCode()) {
serviceId = obj.getInteger("data");
} else {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), ResultCodeEnum.FAIL.getMsg());
}
//减少服务商库存
ResultObject result = reduceDeviceRepertory(serviceId, deviceType, deviceAmount);
ResultObject result = deviceRepertoryService.reduceDeviceRepertory(serviceId, deviceType, deviceAmount);
if (result != null) {
return result;
}
//增加技工库存
addDeviceRepertory(userId, deviceType, deviceAmount);
deviceRepertoryService.addDeviceRepertory(userId, deviceType, deviceAmount);
}
/**
* 确认收货更新订货单设备的入库时间
......@@ -558,84 +556,7 @@ public class IndentServiceImpl implements IndentService {
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg());
}
/**
*
* @author zhanghj
* @Title: addDeviceRepertory
* @Description: TODO 增加用户库存
* @param userId
* @param deviceType
* @param deviceAmount
* void
*
*/
private void addDeviceRepertory(Integer userId, String deviceType, Integer deviceAmount) {
// TODO Auto-generated method stub
SysDeviceRepertory deviceRepertory = new SysDeviceRepertory();
deviceRepertory.setUserId(userId);
deviceRepertory.setDeviceType(deviceType);
SysDeviceRepertory repertory = deviceRepertoryService.get(deviceRepertory);
if (repertory != null) {
Integer deviceNum = repertory.getDeviceNum();
Integer totalDeviceNum = deviceNum + deviceAmount;
deviceRepertory.setDeviceNum(totalDeviceNum);
deviceRepertory.setUpdateTime(new Date());
Integer version = repertory.getVersion();
deviceRepertory.setVersion(version);
int n = deviceRepertoryService.updateSelective(deviceRepertory);
if (n <= 0) {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), ResultCodeEnum.FAIL.getMsg());
}
} else {
deviceRepertory.setDeviceNum(deviceAmount);
deviceRepertory.setCreateTime(new Date());
int n = deviceRepertoryService.insertSelective(deviceRepertory);
if (n <= 0) {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), ResultCodeEnum.FAIL.getMsg());
}
}
}
/**
*
* @author zhanghj
* @Title: reduceDeviceRepertory
* @Description: TODO 减少用户库存
* @param userId
* @param deviceType
* @param deviceAmount
* @return
* ResultObject
*
*/
private ResultObject reduceDeviceRepertory(Integer userId, String deviceType, Integer deviceAmount) {
// TODO Auto-generated method stub
ResultObject result = null;
SysDeviceRepertory deviceRepertory = new SysDeviceRepertory();
deviceRepertory.setUserId(userId);
deviceRepertory.setDeviceType(deviceType);
SysDeviceRepertory repertory = deviceRepertoryService.get(deviceRepertory);
if (repertory == null) {
result = new ResultObject(ResultCodeEnum.DEVICE_REPERTORY_NOT_EXIST.getCode(), ResultCodeEnum.DEVICE_REPERTORY_NOT_EXIST.getMsg());
return result;
}
Integer deviceNum = repertory.getDeviceNum();
if (deviceNum < deviceAmount) {
result = new ResultObject(ResultCodeEnum.DEVICE_REPERTORY_NOT_ENOUGH.getCode(), ResultCodeEnum.DEVICE_REPERTORY_NOT_ENOUGH.getMsg());
return result;
}
Integer totalDeviceNum = deviceNum - deviceAmount;
deviceRepertory.setDeviceNum(totalDeviceNum);
deviceRepertory.setUpdateTime(new Date());
Integer version = repertory.getVersion();
deviceRepertory.setVersion(version);
int n = deviceRepertoryService.updateSelective(deviceRepertory);
if (n <= 0) {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), ResultCodeEnum.FAIL.getMsg());
}
return result;
}
@Override
public List<SysIndent> getMechanicIndentListByPage(
HttpServletRequest request, Page page, SysIndent indent) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!