|
|
|
@ -28,6 +28,7 @@ import cn.hutool.core.lang.Snowflake; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
import java.util.*; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
@ -59,7 +60,6 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
private RedissonClient redissonClient; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 提交申请,插入一条仓库调度记录 |
|
|
|
* |
|
|
|
@ -96,7 +96,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
temp.put("dcode", depositoryRecordById.getCode()); |
|
|
|
// 获取当前仓库库存
|
|
|
|
Double Inventory = depositoryMapper.getToDayInventoryByDName(temp); |
|
|
|
String code = createCode(depositoryRecordById.getDname(), "InOrderNumber","in","");//构造单号
|
|
|
|
String code = createCode(depositoryRecordById.getDname(), "InOrderNumber", "in", "");//构造单号
|
|
|
|
Double quantity = Double.parseDouble((String) map.get("quantity")); |
|
|
|
Double price = Double.parseDouble((String) map.get("price")); |
|
|
|
Integer mid = ObjectFormatUtil.toInteger(map.get("mid")); |
|
|
|
@ -122,8 +122,8 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
// 获取当前物料
|
|
|
|
if (materialByCondition.size() > 0) { // 如果当前存在
|
|
|
|
Material mt = materialByCondition.get(0); |
|
|
|
map.put("oldPrice",mt.getPrice()); |
|
|
|
map.put("mid",mt.getId()); |
|
|
|
map.put("oldPrice", mt.getPrice()); |
|
|
|
map.put("mid", mt.getId()); |
|
|
|
mt.setAmounts(mt.getAmounts() + amounts); |
|
|
|
mt.setQuantity((int) (mt.getQuantity() + quantity)); |
|
|
|
mt.setPrice(avgPrice); |
|
|
|
@ -148,7 +148,6 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 插入一条出库记录 |
|
|
|
* |
|
|
|
@ -156,33 +155,39 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public Integer insertApplicationOutRecord(Map<String, Object> map,UserByPort userToken) { |
|
|
|
public Integer insertApplicationOutRecord(Map<String, Object> map, UserByPort userToken) { |
|
|
|
String placeId = (String) map.get("placeId"); |
|
|
|
if("".equals(placeId) || "0".equals(placeId)){ |
|
|
|
map.put("placeId",0); |
|
|
|
if ("".equals(placeId) || "0".equals(placeId) || placeId == null) { |
|
|
|
map.put("placeId", 0); |
|
|
|
} |
|
|
|
Double quantity = Double.parseDouble((String) map.get("quantity")); |
|
|
|
Long time = DateUtil.DateTimeToTimeStamp(DateUtil.getSimpleTime(new Date())); |
|
|
|
map.put("applicantTime", time); |
|
|
|
Integer mid = ObjectFormatUtil.toInteger(map.get("mid")); |
|
|
|
// 获取当前物料
|
|
|
|
Material materialById = materialMapper.findMaterialById(mid); |
|
|
|
int amounts = (int) ((materialById.getPrice() / 100) * quantity * 100); |
|
|
|
map.put("price", amounts); |
|
|
|
map.put("state", "待部门负责人审核"); |
|
|
|
String dname = ""; |
|
|
|
map.put("istransfer", 2); |
|
|
|
Map<String, Object> update = new HashMap<>(); |
|
|
|
update.put("id", materialById.getId()); |
|
|
|
Integer numberOfTemporary = materialById.getNumberOfTemporary(); |
|
|
|
if (numberOfTemporary == null) { |
|
|
|
numberOfTemporary = 0; |
|
|
|
map.put("state", "待部门负责人审核"); |
|
|
|
if (mid != null) { |
|
|
|
// 获取当前物料
|
|
|
|
Material materialById = materialMapper.findMaterialById(mid); |
|
|
|
int amounts = (int) ((materialById.getPrice() / 100) * quantity * 100); |
|
|
|
map.put("price", amounts); |
|
|
|
Map<String, Object> update = new HashMap<>(); |
|
|
|
update.put("id", materialById.getId()); |
|
|
|
Integer numberOfTemporary = materialById.getNumberOfTemporary(); |
|
|
|
if (numberOfTemporary == null) { |
|
|
|
numberOfTemporary = 0; |
|
|
|
} |
|
|
|
update.put("numberOfTemporary", numberOfTemporary + quantity); |
|
|
|
materialMapper.updateMaterial(update); |
|
|
|
Depository depositoryRecordById = depositoryMapper.findDepositoryRecordById(materialById.getDepositoryId()); |
|
|
|
dname = depositoryRecordById.getDname(); |
|
|
|
} |
|
|
|
update.put("numberOfTemporary", numberOfTemporary + quantity); |
|
|
|
materialMapper.updateMaterial(update); |
|
|
|
Depository depositoryRecordById = depositoryMapper.findDepositoryRecordById(materialById.getDepositoryId()); |
|
|
|
|
|
|
|
Administration company = PageController.getCompany(userToken.getMaindeparment()); |
|
|
|
String code = createCode(depositoryRecordById.getDname(), "outOrderNumber","out",company.getName()); |
|
|
|
String code = createCode(dname, "outOrderNumber", "out", company.getName()); |
|
|
|
map.put("code", code); |
|
|
|
map.put("pass", 3); |
|
|
|
return depositoryRecordMapper.insertApplicationOutRecord(map); |
|
|
|
} |
|
|
|
|
|
|
|
@ -250,37 +255,37 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
// 获取当前物料基本信息
|
|
|
|
Integer mid = ObjectFormatUtil.toInteger(map.get("mid")); |
|
|
|
Material materialById = materialMapper.findMaterialById(mid); |
|
|
|
if(placeById.getMax() - placeById.getQuantity() > quantity){ |
|
|
|
if (placeById.getMax() - placeById.getQuantity() > quantity) { |
|
|
|
// 如果当前库位还能存放
|
|
|
|
|
|
|
|
// 入库
|
|
|
|
Integer integer = applicationIn(map); |
|
|
|
if(integer != 1){ |
|
|
|
if (integer != 1) { |
|
|
|
return -1; |
|
|
|
} |
|
|
|
// 获取当前库存记录
|
|
|
|
Map<String, Object> param = new HashMap<>(); |
|
|
|
param.put("code", materialById.getCode()); |
|
|
|
param.put("mname", materialById.getMname()); |
|
|
|
if(placeId == 0){ |
|
|
|
param.put("depositoryId",map.get("depositoryId")); |
|
|
|
}else { |
|
|
|
if (placeId == 0) { |
|
|
|
param.put("depositoryId", map.get("depositoryId")); |
|
|
|
} else { |
|
|
|
param.put("depositoryId", placeById.getDid()); |
|
|
|
} |
|
|
|
List<Material> inventory = materialMapper.findInventory(param); |
|
|
|
Material material = inventory.get(0); |
|
|
|
|
|
|
|
Map<String,Object> insert = new HashMap<>(); |
|
|
|
insert.put("mid",material.getId()); |
|
|
|
insert.put("pid",placeById.getId()); |
|
|
|
Map<String, Object> insert = new HashMap<>(); |
|
|
|
insert.put("mid", material.getId()); |
|
|
|
insert.put("pid", placeById.getId()); |
|
|
|
|
|
|
|
MaterialAndPlace placeAndMaterialByMidAndPid = placeMapper.findPlaceAndMaterialByMidAndPid(insert); |
|
|
|
if(placeAndMaterialByMidAndPid == null){ |
|
|
|
if (placeAndMaterialByMidAndPid == null) { |
|
|
|
// 如果没有当前记录
|
|
|
|
insert.put("quantity",quantity); |
|
|
|
insert.put("quantity", quantity); |
|
|
|
// 插入记录
|
|
|
|
placeMapper.addMaterialOnPlace(insert); |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
placeAndMaterialByMidAndPid.setQuantity(placeAndMaterialByMidAndPid.getQuantity() + quantity); |
|
|
|
// 修改数量
|
|
|
|
placeMapper.updateMaterialAndPlace(placeAndMaterialByMidAndPid); |
|
|
|
@ -288,13 +293,14 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
// 修改当前库位数量
|
|
|
|
placeById.setQuantity(placeById.getQuantity() + quantity); |
|
|
|
return placeMapper.UpdatePlace(placeById); |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
return -1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 将刚入库的记录删除 |
|
|
|
* |
|
|
|
* @param map |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@ -308,34 +314,34 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
Material materialById = materialMapper.findMaterialById(mid); |
|
|
|
Object oldPrice1 = map.get("oldPrice"); |
|
|
|
Double oldPrice = 0.0; |
|
|
|
if(oldPrice1 != null) { |
|
|
|
oldPrice = Double.parseDouble(oldPrice1.toString()); |
|
|
|
if (oldPrice1 != null) { |
|
|
|
oldPrice = Double.parseDouble(oldPrice1.toString()); |
|
|
|
} |
|
|
|
Double price = Double.parseDouble(map.get("price").toString()); |
|
|
|
Integer id = ObjectFormatUtil.toInteger(map.get("id")); |
|
|
|
String deleteType = map.get("delete").toString(); |
|
|
|
Map<String,Object> params = new HashMap<>(); |
|
|
|
params.put("code",materialById.getCode()); |
|
|
|
params.put("depositoryId",depositoryId); |
|
|
|
Map<String, Object> params = new HashMap<>(); |
|
|
|
params.put("code", materialById.getCode()); |
|
|
|
params.put("depositoryId", depositoryId); |
|
|
|
List<Material> materialByCondition = materialMapper.findMaterialByCondition(params); |
|
|
|
if(materialByCondition.size() < 1){ |
|
|
|
if (materialByCondition.size() < 1) { |
|
|
|
throw new MyException("出现未知错误,联系开发人员"); |
|
|
|
} |
|
|
|
if("in".equals(deleteType)){ |
|
|
|
if ("in".equals(deleteType)) { |
|
|
|
// 删除入库记录
|
|
|
|
depositoryRecordMapper.deleteApplicationInRecordById(id); |
|
|
|
// 将库存还原
|
|
|
|
Material material = materialByCondition.get(0); |
|
|
|
Map<String,Object> update = new HashMap<>(); |
|
|
|
update.put("quantity",material.getQuantity() - quantity); |
|
|
|
update.put("price",oldPrice); |
|
|
|
update.put("amounts",material.getAmounts() - quantity * price); |
|
|
|
update.put("id",material.getId()); |
|
|
|
Map<String, Object> update = new HashMap<>(); |
|
|
|
update.put("quantity", material.getQuantity() - quantity); |
|
|
|
update.put("price", oldPrice); |
|
|
|
update.put("amounts", material.getAmounts() - quantity * price); |
|
|
|
update.put("id", material.getId()); |
|
|
|
return materialMapper.updateMaterial(update); |
|
|
|
|
|
|
|
}else if("out".equals(deleteType)){ |
|
|
|
} else if ("out".equals(deleteType)) { |
|
|
|
return null; |
|
|
|
}else { |
|
|
|
} else { |
|
|
|
throw new MyException("请求参数错误"); |
|
|
|
} |
|
|
|
|
|
|
|
@ -343,16 +349,21 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
|
|
|
|
/** |
|
|
|
* 插入一条出库子订单 |
|
|
|
* |
|
|
|
* @param map |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public Integer insertApplicationOutMin(Map<String, Object> map) { |
|
|
|
Integer mid = ObjectFormatUtil.toInteger(map.get("mid")); |
|
|
|
Material materialById = materialMapper.findMaterialById(mid); |
|
|
|
map.put("depositoryId", materialById.getDepositoryId()); |
|
|
|
return depositoryRecordMapper.insertApplicationOutRecordMin(map); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据主表获取所有子表 |
|
|
|
* |
|
|
|
* @param id |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@ -361,6 +372,184 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
return depositoryRecordMapper.findApplicationOutRecordMinByParent(id); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据主键获取子表信息 |
|
|
|
* |
|
|
|
* @param id |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public ApplicationOutRecordMin findApplicationOutMinById(Integer id) { |
|
|
|
return depositoryRecordMapper.findApplicationOutMinById(id); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据条件获取子订单 |
|
|
|
* |
|
|
|
* @param map |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public List<ApplicationOutRecordMin> findApplicationOutMinByCondition(Map<String, Object> map) { |
|
|
|
return depositoryRecordMapper.findApplicationOutMinByCondition(map); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据主订单获取子订单 |
|
|
|
* @param parentId |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public List<ApplicationOutRecordMin> findApplicationOutMinByParentId(Integer parentId) { |
|
|
|
Map<String,Object> map = new HashMap<>(); |
|
|
|
map.put("parentId",parentId); |
|
|
|
return depositoryRecordMapper.findApplicationOutMinByCondition(map); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 完成对应的子订单 |
|
|
|
* |
|
|
|
* @param param |
|
|
|
* @param userByPort |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public Integer completeApplicationOutMinRecord(Map<String,Object> param, UserByPort userByPort) { |
|
|
|
Integer id = ObjectFormatUtil.toInteger(param.get("id")); |
|
|
|
|
|
|
|
// 获取要完成的子订单
|
|
|
|
ApplicationOutRecordMin applicationOutMinById = depositoryRecordMapper.findApplicationOutMinById(id); |
|
|
|
// 获取子订单对应的主订单
|
|
|
|
ApplicationOutRecordP record = depositoryRecordMapper.findApplicationOutRecordPById(applicationOutMinById.getParentId()); |
|
|
|
// 设置标志位
|
|
|
|
boolean flag = true; |
|
|
|
// 设置最终返回值
|
|
|
|
int result = 0; |
|
|
|
// 获取库存转移标志位
|
|
|
|
Integer istransfer = record.getIstransfer(); |
|
|
|
// 获取出库库位
|
|
|
|
Integer placeId = ObjectFormatUtil.toInteger(param.get("placeId")); |
|
|
|
if (istransfer == 1) {// 如果是库存转移
|
|
|
|
// 获取库存转移订单
|
|
|
|
TransferRecord transferRecordById = transferRecordMapper.findTransferRecordById(record.getTransferId()); |
|
|
|
placeId = transferRecordById.getFromPlaceId();// 获取转出库位
|
|
|
|
} |
|
|
|
MaterialAndPlace placeAndMaterialByMidAndPid = null; |
|
|
|
if (placeId != 0) { // 如果不是默认库位
|
|
|
|
Map<String, Object> params = new HashMap<>(); |
|
|
|
params.put("mid", applicationOutMinById.getMid()); |
|
|
|
params.put("pid", placeId); |
|
|
|
// 获取当前物料所存放库位的数量
|
|
|
|
placeAndMaterialByMidAndPid = placeMapper.findPlaceAndMaterialByMidAndPid(params); |
|
|
|
if (placeAndMaterialByMidAndPid.getQuantity() < record.getQuantity()) { |
|
|
|
// 如果当前库位数量不足
|
|
|
|
flag = false; |
|
|
|
} |
|
|
|
} else { // 如果是默认库位
|
|
|
|
Map<String, Object> params = new HashMap<>(); |
|
|
|
params.put("mid", applicationOutMinById.getMid()); |
|
|
|
params.put("pid", 0); |
|
|
|
// 获取当前物料在默认库位中的数量
|
|
|
|
placeAndMaterialByMidAndPid = placeMapper.findPlaceAndMaterialByMidAndPid(params); |
|
|
|
if (placeAndMaterialByMidAndPid.getQuantity() < record.getQuantity()) { |
|
|
|
// 如果当前库位数量不足
|
|
|
|
flag = false; |
|
|
|
} |
|
|
|
} |
|
|
|
// 获取出库物料具体信息
|
|
|
|
Material material = materialMapper.findMaterialById(applicationOutMinById.getMid()); |
|
|
|
// 如果物料数量可以出库并且库位数量充足
|
|
|
|
if (material.getQuantity() >= record.getQuantity() && flag) { |
|
|
|
// 当前出库金额
|
|
|
|
Double sum = material.getPrice() * record.getQuantity(); |
|
|
|
material.setAmounts(material.getAmounts() - sum); |
|
|
|
material.setQuantity(material.getQuantity() - record.getQuantity()); |
|
|
|
material.setNumberOfTemporary(material.getNumberOfTemporary() - record.getQuantity()); |
|
|
|
// 修改物料信息
|
|
|
|
materialMapper.updateMaterial(material); |
|
|
|
|
|
|
|
if (placeAndMaterialByMidAndPid != null) { //如果库位不为空
|
|
|
|
// 修改当前库位存放物料的数量
|
|
|
|
placeAndMaterialByMidAndPid.setQuantity(placeAndMaterialByMidAndPid.getQuantity() - record.getQuantity()); |
|
|
|
placeMapper.updateMaterialAndPlace(placeAndMaterialByMidAndPid); |
|
|
|
} |
|
|
|
|
|
|
|
// 修改库位数量
|
|
|
|
Place placeById = placeMapper.findPlaceById(placeId); |
|
|
|
placeById.setQuantity(placeById.getQuantity() - record.getQuantity()); |
|
|
|
placeMapper.UpdatePlace(placeById); |
|
|
|
|
|
|
|
|
|
|
|
String redisMinRecordKey = "minRecord:"+id; // 设置redis中子订单键值
|
|
|
|
// 修改redis中本子订单状态
|
|
|
|
redisTemplate.opsForHash().put(redisMinRecordKey,"state","2"); |
|
|
|
// 修改redis中本子订单完成人
|
|
|
|
redisTemplate.opsForHash().put(redisMinRecordKey,"manager",userByPort.getId().toString()); |
|
|
|
// 获取出库仓库信息
|
|
|
|
Depository depositoryRecordById = depositoryMapper.findDepositoryRecordById(applicationOutMinById.getDepositoryId()); |
|
|
|
// 设置子订单新编码
|
|
|
|
// 获取主订单单号
|
|
|
|
StringBuilder code = new StringBuilder(record.getCode()); |
|
|
|
// 获取申请用户信息
|
|
|
|
UserByPort applicantUser = PageController.FindUserById(record.getApplicantId()); |
|
|
|
// 获取申请用户行政组织
|
|
|
|
Administration company = PageController.getCompany(applicantUser.getMaindeparment()); |
|
|
|
// 获取部门名称简写
|
|
|
|
String conpanyName = WordUtil.getPinYinHeadChar(company.getName()); |
|
|
|
// 获取仓库名称简写
|
|
|
|
String depositoryName = WordUtil.getPinYinHeadChar(depositoryRecordById.getDname()); |
|
|
|
// 获取部门名称在单号的起始位置
|
|
|
|
int index = code.indexOf(conpanyName); |
|
|
|
// 生产新子订单编号
|
|
|
|
String newCode = code.replace(index,index+conpanyName.length(),depositoryName).toString(); |
|
|
|
// 设置完成人
|
|
|
|
applicationOutMinById.setCheckId(userByPort.getId()); |
|
|
|
// 设置新编码
|
|
|
|
applicationOutMinById.setCode(newCode); |
|
|
|
// 设置新库位
|
|
|
|
applicationOutMinById.setPlaceId(placeId); |
|
|
|
// 修改子订单
|
|
|
|
result += depositoryRecordMapper.updateApplicationOutRecordMin(applicationOutMinById); |
|
|
|
|
|
|
|
|
|
|
|
String redisMainRecordKey = "record:"+record.getId(); // 设置redis中主订单键值
|
|
|
|
// 获取redis中主订单的所有子订单
|
|
|
|
String minRecordList = (String) redisTemplate.opsForHash().get(redisMainRecordKey, "minRecord"); |
|
|
|
// 获取所有子订单键值
|
|
|
|
String[] split = minRecordList.replace("[", "").replace("]", "").split(","); |
|
|
|
int pass = 1; // 设置主订单最终状态
|
|
|
|
for (int i = 0; i < split.length; i++) { |
|
|
|
// 获取所有子订单状态
|
|
|
|
String state = (String) redisTemplate.opsForHash().get(split[i], "state"); |
|
|
|
if("1".equals(state)){ |
|
|
|
// 如果有子订单未完成
|
|
|
|
pass = 3; // 设置主订单状态为处理中
|
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
if(pass == 1){ // 如果最终状态为完成
|
|
|
|
Map<String,Object> map = new HashMap<>(); |
|
|
|
map.put("pass",pass); |
|
|
|
map.put("id",record.getId()); |
|
|
|
// 修改状态为完成
|
|
|
|
depositoryRecordMapper.updateApplicationOutRecord(map); |
|
|
|
} |
|
|
|
|
|
|
|
// 如果是库存转移订单
|
|
|
|
Map<String,Object> map = new HashMap<>(); |
|
|
|
if (record.getIstransfer() == 1) { |
|
|
|
map.put("quantity", record.getQuantity().toString()); |
|
|
|
map.put("applicantId", record.getApplicantId()); |
|
|
|
map.put("transferId", record.getTransferId()); |
|
|
|
transferMaterial(map); |
|
|
|
} |
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 转移申请 |
|
|
|
* |
|
|
|
@ -369,7 +558,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public Integer transferApply(Map<String, Object> map,UserByPort userByPort) { |
|
|
|
public Integer transferApply(Map<String, Object> map, UserByPort userByPort) { |
|
|
|
Integer mid = ObjectFormatUtil.toInteger(map.get("mid")); |
|
|
|
Double quantity = Double.parseDouble((String) map.get("quantity")); |
|
|
|
Material material = materialMapper.findMaterialById(mid); |
|
|
|
@ -383,12 +572,12 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
map.put("fromId", material.getDepositoryId()); |
|
|
|
String fromPlaceId = (String) map.get("fromPlaceId"); |
|
|
|
String toPlaceId = (String) map.get("placeId"); |
|
|
|
if("".equals(fromPlaceId) || "0".equals(fromPlaceId)){ |
|
|
|
map.put("fromPlaceId",0); |
|
|
|
if ("".equals(fromPlaceId) || "0".equals(fromPlaceId)) { |
|
|
|
map.put("fromPlaceId", 0); |
|
|
|
} |
|
|
|
map.put("toPlaceId",toPlaceId) ; |
|
|
|
if("".equals(toPlaceId) || "0".equals(toPlaceId)){ |
|
|
|
map.put("toPlaceId",0); |
|
|
|
map.put("toPlaceId", toPlaceId); |
|
|
|
if ("".equals(toPlaceId) || "0".equals(toPlaceId)) { |
|
|
|
map.put("toPlaceId", 0); |
|
|
|
} |
|
|
|
//清除主键
|
|
|
|
// depositoryRecordMapper.insertApplicationInRecord(map);
|
|
|
|
@ -397,10 +586,10 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
map.put("transferId", transferRecordByCondition.getId()); |
|
|
|
Depository depositoryRecordById = depositoryMapper.findDepositoryRecordById(material.getDepositoryId()); |
|
|
|
Administration company = PageController.getCompany(userByPort.getMaindeparment()); |
|
|
|
map.put("code", createCode(depositoryRecordById.getDname(), "outOrderNumber","out",company.getName())); |
|
|
|
map.put("code", createCode(depositoryRecordById.getDname(), "outOrderNumber", "out", company.getName())); |
|
|
|
String placeId = (String) map.get("placeId"); |
|
|
|
if("".equals(placeId)){ |
|
|
|
map.put("placeId",0); |
|
|
|
if ("".equals(placeId)) { |
|
|
|
map.put("placeId", 0); |
|
|
|
} |
|
|
|
//清除主键
|
|
|
|
return depositoryRecordMapper.insertApplicationOutRecord(map); |
|
|
|
@ -437,92 +626,69 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
} else { |
|
|
|
map.put("state", "部门负责人审核未通过"); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
} else { |
|
|
|
String simpleTime = DateUtil.getSimpleTime(new Date()); |
|
|
|
map.put("depositoryManagerTime", DateUtil.DateTimeToTimeStamp(simpleTime)); |
|
|
|
map.put("depositoryManager", userid); |
|
|
|
map.put("depositoryId", record.getDepositoryId()); |
|
|
|
// 获取主单下的子单
|
|
|
|
List<ApplicationOutRecordMin> applicationOutRecordMinByParent = depositoryRecordMapper.findApplicationOutRecordMinByParent(record.getId()); |
|
|
|
for (int i = 0; i < applicationOutRecordMinByParent.size(); i++) { |
|
|
|
|
|
|
|
} |
|
|
|
// map.put("mid", record.getMid());
|
|
|
|
// Material material = materialMapper.findMaterialById(record.getMid());
|
|
|
|
Integer depositoryManagerPass = (Integer) map.get("depositoryManagerPass"); |
|
|
|
if (depositoryManagerPass == 1) { |
|
|
|
/*boolean flag = true; |
|
|
|
Integer istransfer = record.getIstransfer(); |
|
|
|
Integer placeId = record.getPlaceId(); |
|
|
|
if(istransfer == 1){ |
|
|
|
TransferRecord transferRecordById = transferRecordMapper.findTransferRecordById(record.getTransferId()); |
|
|
|
placeId = transferRecordById.getFromPlaceId();// 获取转出库位
|
|
|
|
} |
|
|
|
MaterialAndPlace placeAndMaterialByMidAndPid = null; |
|
|
|
if(placeId != 0){ |
|
|
|
Map<String,Object> params = new HashMap<>(); |
|
|
|
params.put("mid",material.getId()); |
|
|
|
params.put("pid",placeId); |
|
|
|
// 获取当前物料所存放库位的数量
|
|
|
|
placeAndMaterialByMidAndPid = placeMapper.findPlaceAndMaterialByMidAndPid(params); |
|
|
|
if(placeAndMaterialByMidAndPid.getQuantity() < record.getQuantity()){ |
|
|
|
// 如果当前库位数量不足
|
|
|
|
flag = false; |
|
|
|
} |
|
|
|
}else{ |
|
|
|
Map<String,Object> params = new HashMap<>(); |
|
|
|
params.put("mid",material.getId()); |
|
|
|
params.put("pid",0); |
|
|
|
// 获取当前物料在默认库位中的数量
|
|
|
|
placeAndMaterialByMidAndPid = placeMapper.findPlaceAndMaterialByMidAndPid(params); |
|
|
|
if(placeAndMaterialByMidAndPid.getQuantity() < record.getQuantity()){ |
|
|
|
// 如果当前库位数量不足
|
|
|
|
flag = false; |
|
|
|
// 如果审核通过
|
|
|
|
|
|
|
|
// 获取主单下的所有子单
|
|
|
|
StringBuilder minRecordByMain = new StringBuilder("[]"); |
|
|
|
List<ApplicationOutRecordMin> applicationOutRecordMinByParent = depositoryRecordMapper.findApplicationOutRecordMinByParent(record.getId()); |
|
|
|
for (int i = 0; i < applicationOutRecordMinByParent.size(); i++) { |
|
|
|
// 获取子单信息
|
|
|
|
ApplicationOutRecordMin applicationOutRecordMin = applicationOutRecordMinByParent.get(i); |
|
|
|
//设置子订单在redis中的主键
|
|
|
|
String minRecordKey = "minRecord:" + applicationOutRecordMin.getId(); |
|
|
|
minRecordByMain.insert(1, minRecordKey + ","); // 将子订单主键插入到主订单的子订单列表
|
|
|
|
// 设置当前子订单对应仓库管理员记录
|
|
|
|
StringBuilder minRecordManage = new StringBuilder(); |
|
|
|
// 将要存储到redis中的子订单信息
|
|
|
|
Map<String, Object> minRecord = new HashMap<>(); |
|
|
|
minRecord.put("parentId", record.getId().toString()); // 当前子订单主订单
|
|
|
|
minRecord.put("state", "1"); // 当前子订单状态 1待处理2处理
|
|
|
|
// 获取对应的物料编号
|
|
|
|
Integer mid = applicationOutRecordMin.getMid(); |
|
|
|
// 获取物料信息
|
|
|
|
Material materialById = materialMapper.findMaterialById(mid); |
|
|
|
// 获取该物料所处仓库的仓库管理员
|
|
|
|
List<Integer> userIdByDid = new ArrayList<>(); |
|
|
|
userIdByDid = roleService.findUserIdByDid(materialById.getDepositoryId()); |
|
|
|
for (int j = 0; j < userIdByDid.size(); j++) { |
|
|
|
// 仓库管理员订单信息
|
|
|
|
Map<String, Object> userRecord = new HashMap<>(); |
|
|
|
// 用户当前子订单
|
|
|
|
String userMinRecord = (String) redisTemplate.opsForHash().get("user:" + userIdByDid.get(j), "minRecord"); |
|
|
|
if (userMinRecord == null) { // 如果当前用户没有子订单
|
|
|
|
userRecord.put("minRecord", "[" + minRecordKey + "]"); // 插入一条子订单
|
|
|
|
} else { // 如果当前用户已经有子订单
|
|
|
|
StringBuilder minRecordList = new StringBuilder(userMinRecord); // 转为stringbuilder类型
|
|
|
|
minRecordList.insert(1, minRecordKey + ",");// 将当前子订单插入头部
|
|
|
|
userRecord.put("minRecord", minRecordList.toString()); |
|
|
|
} |
|
|
|
// 更新redis中用户记录
|
|
|
|
redisTemplate.opsForHash().putAll("user:" + userIdByDid.get(j), userRecord); |
|
|
|
minRecordManage.append(userIdByDid.get(j)).append(","); |
|
|
|
} |
|
|
|
minRecord.put("manager", minRecordManage.toString()); |
|
|
|
// 添加子订单到redis中
|
|
|
|
redisTemplate.opsForHash().putAll(minRecordKey, minRecord); |
|
|
|
} |
|
|
|
if (material.getQuantity() >= record.getQuantity() && flag) { |
|
|
|
// 当前出库金额
|
|
|
|
Double sum = material.getPrice() * record.getQuantity(); |
|
|
|
material.setAmounts(material.getAmounts() - sum); |
|
|
|
material.setQuantity(material.getQuantity() - record.getQuantity()); |
|
|
|
material.setNumberOfTemporary(material.getNumberOfTemporary() - record.getQuantity()); |
|
|
|
materialMapper.updateMaterial(material); |
|
|
|
|
|
|
|
if(placeAndMaterialByMidAndPid != null){ |
|
|
|
// 修改当前库位存放物料的数量
|
|
|
|
placeAndMaterialByMidAndPid.setQuantity(placeAndMaterialByMidAndPid.getQuantity() - record.getQuantity()); |
|
|
|
placeMapper.updateMaterialAndPlace(placeAndMaterialByMidAndPid); |
|
|
|
} |
|
|
|
|
|
|
|
// 修改库位数量
|
|
|
|
Place placeById = placeMapper.findPlaceById(placeId); |
|
|
|
placeById.setQuantity(placeById.getQuantity() - record.getQuantity()); |
|
|
|
placeMapper.UpdatePlace(placeById); |
|
|
|
|
|
|
|
if (record.getIstransfer() == 1) { |
|
|
|
map.put("quantity", record.getQuantity().toString()); |
|
|
|
map.put("applicantId", record.getApplicantId()); |
|
|
|
map.put("transferId", record.getTransferId()); |
|
|
|
transferMaterial(map); |
|
|
|
} |
|
|
|
} else { |
|
|
|
map.put("state", "未出库"); |
|
|
|
map.put("depositoryManagerMessage", "当前仓位库存量不足"); |
|
|
|
Map<String, Object> update = new HashMap<>(); |
|
|
|
// update.put("id", material.getId());
|
|
|
|
update.put("numberOfTemporary", 0); |
|
|
|
materialMapper.updateMaterial(update); |
|
|
|
depositoryRecordMapper.updateApplicationOutRecord(map); |
|
|
|
return -1; |
|
|
|
} |
|
|
|
*/ |
|
|
|
map.put("state", "出库中"); |
|
|
|
// 将主订单插入到redis中
|
|
|
|
redisTemplate.opsForHash().put("record:" + record.getId(), "minRecord", minRecordByMain.toString()); |
|
|
|
map.put("state", "仓储中心负责人审核通过"); |
|
|
|
} else { |
|
|
|
map.put("pass", 2); |
|
|
|
map.put("state", "仓储中心负责人审核未通过"); |
|
|
|
} |
|
|
|
} |
|
|
|
map.put("id",id); |
|
|
|
map.put("id", id); |
|
|
|
return depositoryRecordMapper.updateApplicationOutRecord(map); |
|
|
|
} |
|
|
|
|
|
|
|
@ -543,9 +709,9 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
List<Material> materiallist = materialMapper.findInventory(param); |
|
|
|
if (materiallist.size() > 0) { |
|
|
|
// 如果在该仓库
|
|
|
|
map.put("price",material.getPrice().toString()); |
|
|
|
map.put("price", material.getPrice().toString()); |
|
|
|
map.put("depositoryId", transferRecor.getToId()); |
|
|
|
map.put("placeId",transferRecor.getToPlaceId()); |
|
|
|
map.put("placeId", transferRecor.getToPlaceId()); |
|
|
|
applicationInPlace(map); |
|
|
|
map.put("mid", materiallist.get(0).getId()); |
|
|
|
} else { |
|
|
|
@ -567,34 +733,34 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
materialMapper.insertMaterial(insert); |
|
|
|
|
|
|
|
// 查询该记录
|
|
|
|
Map<String,Object> temp = new HashMap<>(); |
|
|
|
temp.put("code",materialById.getCode()); |
|
|
|
temp.put("depositoryId",transferRecor.getToId()); |
|
|
|
temp.put("mname",materialById.getMname()); |
|
|
|
Map<String, Object> temp = new HashMap<>(); |
|
|
|
temp.put("code", materialById.getCode()); |
|
|
|
temp.put("depositoryId", transferRecor.getToId()); |
|
|
|
temp.put("mname", materialById.getMname()); |
|
|
|
List<Material> inventoryList = materialMapper.findInventory(temp); |
|
|
|
// 获取该库存记录
|
|
|
|
Material inventory = inventoryList.get(0); |
|
|
|
|
|
|
|
Map<String,Object> fromPlaceTemp = new HashMap<>(); |
|
|
|
Map<String,Object> toPlaceTemp = new HashMap<>(); |
|
|
|
Map<String, Object> fromPlaceTemp = new HashMap<>(); |
|
|
|
Map<String, Object> toPlaceTemp = new HashMap<>(); |
|
|
|
// 转入库位
|
|
|
|
Place toPlace = placeMapper.findPlaceById(transferRecor.getToPlaceId()); |
|
|
|
toPlace.setQuantity(toPlace.getQuantity() + quantity); |
|
|
|
placeMapper.UpdatePlace(toPlace); // 修改转入库位额度
|
|
|
|
toPlaceTemp.put("mid",materialById.getId()); |
|
|
|
toPlaceTemp.put("pid",toPlace.getId()); |
|
|
|
toPlaceTemp.put("quantity",quantity); |
|
|
|
toPlaceTemp.put("mid", materialById.getId()); |
|
|
|
toPlaceTemp.put("pid", toPlace.getId()); |
|
|
|
toPlaceTemp.put("quantity", quantity); |
|
|
|
// 获取转入物料具体所在库位
|
|
|
|
MaterialAndPlace toMaterialAndPlace = placeMapper.findPlaceAndMaterialByMidAndPid(toPlaceTemp); |
|
|
|
if(toMaterialAndPlace == null){ |
|
|
|
if (toMaterialAndPlace == null) { |
|
|
|
placeMapper.addMaterialOnPlace(toPlaceTemp); |
|
|
|
} |
|
|
|
// 转出库位
|
|
|
|
Place fromPlace = placeMapper.findPlaceById(transferRecor.getFromPlaceId()); |
|
|
|
fromPlace.setQuantity(fromPlace.getQuantity() - quantity); |
|
|
|
placeMapper.UpdatePlace(fromPlace); // 修改转出库位额度
|
|
|
|
fromPlaceTemp.put("mid",materialById.getId()); |
|
|
|
fromPlaceTemp.put("pid",toPlace.getId()); |
|
|
|
fromPlaceTemp.put("mid", materialById.getId()); |
|
|
|
fromPlaceTemp.put("pid", toPlace.getId()); |
|
|
|
// 获取转出物料具体所在库位
|
|
|
|
MaterialAndPlace fromMaterialAndPlace = placeMapper.findPlaceAndMaterialByMidAndPid(fromPlaceTemp); |
|
|
|
fromMaterialAndPlace.setQuantity(fromMaterialAndPlace.getQuantity() - quantity); |
|
|
|
@ -1178,7 +1344,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
JSONObject paramObject = JSONObject.parseObject(jsonString); |
|
|
|
String post = null; |
|
|
|
try { |
|
|
|
post = HttpUtils.send(url, paramObject, HTTP.UTF_8); |
|
|
|
post = HttpUtils.send(url, paramObject, StandardCharsets.UTF_8.toString()); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
@ -1194,7 +1360,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
* @param depositoryName |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private String createCode(String depositoryName, String key,String type,String mainDeparmentName) { |
|
|
|
private String createCode(String depositoryName, String key, String type, String mainDeparmentName) { |
|
|
|
RLock lock = redissonClient.getLock(key); |
|
|
|
// 入库单号(公司简称+仓库简称+年月日+数字(位数设置>=9))
|
|
|
|
String code = "GK"; |
|
|
|
@ -1210,10 +1376,9 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
redisTemplate.boundValueOps(key).set(String.valueOf(newNumber), DateUtil.getSecondsNextEarlyMorning(), TimeUnit.SECONDS); |
|
|
|
lock.unlock(); |
|
|
|
orderNumber = String.format("%09d", ObjectFormatUtil.toInteger(orderNumber)); |
|
|
|
if("in".equals(type)){ |
|
|
|
if ("in".equals(type)) { |
|
|
|
code = code + depositoryName + nowTime + orderNumber; |
|
|
|
} |
|
|
|
else if("out".equals(type)){ |
|
|
|
} else if ("out".equals(type)) { |
|
|
|
mainDeparmentName = WordUtil.getPinYinHeadChar(mainDeparmentName); |
|
|
|
code = code + mainDeparmentName + nowTime + orderNumber; |
|
|
|
} |
|
|
|
|