|
@@ -6,6 +6,7 @@ import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import com.mysql.cj.xdevapi.JsonString;
|
|
|
import com.tld.excel.ExcelUtils;
|
|
|
+import com.tld.mapper.AskGoodsMapper;
|
|
|
import com.tld.mapper.ErrorMapper;
|
|
|
import com.tld.mapper.UserMapper;
|
|
|
import com.tld.mapper.WarehousingMapper;
|
|
@@ -15,6 +16,8 @@ import com.tld.service.WarehousingService;
|
|
|
import com.tld.util.DateUtil;
|
|
|
import com.tld.util.HttpClientUtil;
|
|
|
import org.apache.http.ParseException;
|
|
|
+import org.redisson.api.RLock;
|
|
|
+import org.redisson.api.RedissonClient;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -35,9 +38,12 @@ public class WarehousingServiceImpl implements WarehousingService {
|
|
|
|
|
|
@Autowired
|
|
|
private ErrorMapper errorMapper;
|
|
|
+ //redis锁
|
|
|
+ @Autowired
|
|
|
+ private RedissonClient redissonClient;
|
|
|
|
|
|
-// @Resource
|
|
|
-// private HttpClientUtil httpClientUtil;
|
|
|
+ @Autowired
|
|
|
+ private AskGoodsMapper askGoodsMapper;
|
|
|
|
|
|
@Override
|
|
|
public Map<String, Object> getRecommend(String wllbCode, String suppId, String num, String unique, String producDate) {
|
|
@@ -239,7 +245,8 @@ public class WarehousingServiceImpl implements WarehousingService {
|
|
|
list.add(BillItems);
|
|
|
strJson.put("BillItems", list);
|
|
|
returnData.put("strJson", JSON.toJSONString(strJson));
|
|
|
- System.out.println(returnData);
|
|
|
+
|
|
|
+
|
|
|
HttpClientUtil httpClientUtil1 = new HttpClientUtil();
|
|
|
Map<String, Object> result = httpClientUtil1.doPost("http://42.159.85.29:52480/cwbase/sg/V1/ERP/TELD/DEVTEST/API_WMS_PurInStock/CreatePurInStock", returnData);
|
|
|
if(Integer.parseInt(result.get("msg").toString()) != 200){
|
|
@@ -314,6 +321,182 @@ public class WarehousingServiceImpl implements WarehousingService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> getNotice(Notice notice) {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ try{
|
|
|
+ PageHelper.startPage(notice.getPage(), notice.getLimit());
|
|
|
+ PageInfo<Notice> list = new PageInfo<>(warehousingMapper.getNotice(notice));
|
|
|
+ map.put("data", list);
|
|
|
+ map.put("msg", "200");
|
|
|
+ } catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ map.put("msg", "500");
|
|
|
+ map.put("errMsg", "服务器请求异常,请稍后再试");
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> addInventoryNotice(Notice notice) {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ try{
|
|
|
+ Notice notice1 = warehousingMapper.getNoticeId(notice);
|
|
|
+ if(notice1.getType().equals("1")){
|
|
|
+ map.put("msg", "500");
|
|
|
+ map.put("errMsg", "此通知单已入库!");
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+// if(Double.parseDouble(notice1.getNum()) < Double.parseDouble(notice.getNum())){
|
|
|
+// map.put("msg", "500");
|
|
|
+// map.put("errMsg", "入库数量大于通知单数量!");
|
|
|
+// return map;
|
|
|
+// }
|
|
|
+ if(warehousingMapper.getInventoryNotice(notice) != 0){
|
|
|
+ warehousingMapper.updateInventoryNotice(notice);
|
|
|
+ } else {
|
|
|
+ warehousingMapper.addInventoryNotice(notice);
|
|
|
+ }
|
|
|
+ //入库流水
|
|
|
+ WarehousingVirtual warehousingVirtual = new WarehousingVirtual()
|
|
|
+ .setWllbCode(notice1.getMaterialCode())
|
|
|
+ .setUserId(notice.getUserId())
|
|
|
+ .setStorageLocationCode("000000")
|
|
|
+ .setProducDate(notice1.getNoticeTime())
|
|
|
+ .setNum(notice.getNum());
|
|
|
+ warehousingMapper.addProduct(warehousingVirtual);//入库流水 半成品
|
|
|
+
|
|
|
+ //存入给gs的返回数据
|
|
|
+ String storageCode = codeGenerateRk();
|
|
|
+ ReturnWarehousing returnWarehousing = new ReturnWarehousing()
|
|
|
+ .setStorageCode(storageCode)//入库编号
|
|
|
+ .setSourceType(notice1.getSourceType())//来源类型
|
|
|
+ .setMoveType(notice1.getMoveType())//移动类型
|
|
|
+ .setOrderNumber(notice1.getNoticeId())//通知单id
|
|
|
+ .setWbs(notice1.getWbs())//wbs
|
|
|
+ .setEntryNumber(notice1.getEntryNumber())//gs分录号
|
|
|
+ .setMaterialId(notice1.getMaterialId())//物料id
|
|
|
+ .setId(notice1.getId())//分录单id
|
|
|
+ .setWarehousingNum(notice.getWarehousingNum());//入库数量
|
|
|
+ warehousingMapper.addReturnWarehousing(returnWarehousing);
|
|
|
+ map.put("data", storageCode);
|
|
|
+ map.put("msg", "200");
|
|
|
+ } catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ map.put("msg", "500");
|
|
|
+ map.put("errMsg", "服务器请求异常,请稍后再试");
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> updateInventoryNotice(Notice notice) {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ //redis并发锁
|
|
|
+ RLock lock = redissonClient.getLock(notice.getMaterialId());
|
|
|
+ lock.lock();
|
|
|
+ try{
|
|
|
+ Inventory inventory = warehousingMapper.getHalfInventory(notice);//库存信息
|
|
|
+ AskGoods askGoods = warehousingMapper.getAskGoodsHalf(notice);//要货单信息
|
|
|
+ if(Double.parseDouble(askGoods.getNum()) < Double.parseDouble(notice.getWarehousingNum())){
|
|
|
+ map.put("msg", "500");
|
|
|
+ map.put("errMsg", "出库数量大于要货单数量");
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ if(inventory == null){
|
|
|
+ map.put("msg", "500");
|
|
|
+ map.put("errMsg", "没有查询到此半成品物料的库存");
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ if(Double.parseDouble(notice.getWarehousingNum()) > Double.parseDouble(inventory.getAmount())){
|
|
|
+ map.put("msg", "500");
|
|
|
+ map.put("errMsg", "库存不足");
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ if(Double.parseDouble(notice.getWarehousingNum()) == Double.parseDouble(inventory.getAmount())){
|
|
|
+ warehousingMapper.delInventoryNotice(notice);
|
|
|
+ } else {
|
|
|
+ warehousingMapper.updateInventoryNoticeNum(notice);
|
|
|
+ }
|
|
|
+ warehousingMapper.updateAskGoodsHalf(askGoods.getId(), notice.getWarehousingNum());//修改要货单出库数量
|
|
|
+ //新增半成品出库流水
|
|
|
+ AskGoods askGoods1 = new AskGoods()
|
|
|
+ .setMaterialId(notice.getMaterialId())
|
|
|
+ .setNum(notice.getWarehousingNum())
|
|
|
+ .setUserId(notice.getUserId())
|
|
|
+ .setAskGoodsId(askGoods.getAskGoodsId())
|
|
|
+ .setDepartment(askGoods.getDepartment());//新增出库流水
|
|
|
+ warehousingMapper.addRemovalHalfProduct(askGoods1);
|
|
|
+ //新增返回gs信息
|
|
|
+ String removalCode = codeGenerateCk();
|
|
|
+ ReturRemoval returRemoval = new ReturRemoval()
|
|
|
+ .setMaterialId(notice.getMaterialId())
|
|
|
+ .setAskGoodsId(notice.getAskGoodsId())
|
|
|
+ .setWbs(askGoods.getWbs())
|
|
|
+ .setNum(notice.getWarehousingNum())
|
|
|
+ .setEntryNumber(askGoods.getEntryNumber())
|
|
|
+ .setAskId(askGoods.getId())
|
|
|
+ .setStorageLocationCode(inventory.getStorageLocationCode())
|
|
|
+ .setRemovalCode(removalCode)
|
|
|
+ .setSourceType(askGoods.getSourceType())
|
|
|
+ .setMoveType(askGoods.getMoveType());
|
|
|
+ askGoodsMapper.addReturnGsRemovalF(returRemoval);//新增返回gs数据父表信息
|
|
|
+ askGoodsMapper.addReturnGsRemoval(returRemoval);//新增返回gs数据子表信息
|
|
|
+ map.put("msg", "200");
|
|
|
+ } catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ map.put("msg", "500");
|
|
|
+ map.put("errMsg", "服务器请求异常,请稍后再试");
|
|
|
+ } finally {
|
|
|
+ //释放锁
|
|
|
+ lock.unlock();
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> getProduct(Notice notice) {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ try{
|
|
|
+ PageHelper.startPage(notice.getPage(), notice.getLimit());
|
|
|
+ PageInfo<Notice> list = new PageInfo<>(warehousingMapper.getProduct(notice));
|
|
|
+ map.put("data", list);
|
|
|
+ map.put("msg", "200");
|
|
|
+ } catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ map.put("msg", "500");
|
|
|
+ map.put("errMsg", "服务器请求异常,请稍后再试");
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void productExcel(Notice notice, HttpServletResponse response) {
|
|
|
+ try{
|
|
|
+ //导出数据汇总
|
|
|
+ List<List<Object>> sheetDataList = new ArrayList<>();
|
|
|
+ //表头数据
|
|
|
+ List<Object> head = Arrays.asList("物料名称", "生产时间", "数量", "用户名称", "入库时间");
|
|
|
+ //查询数据
|
|
|
+ PageHelper.startPage(notice.getPage(), notice.getLimit());
|
|
|
+ PageInfo<Map<String, Object>> list = new PageInfo<>(warehousingMapper.productExcel(notice));
|
|
|
+ sheetDataList.add(head);
|
|
|
+ for(Map<String, Object> userMap : list.getList()){
|
|
|
+ List<Object> listSheet = new ArrayList<>();
|
|
|
+ for(String key: userMap.keySet()){
|
|
|
+ listSheet.add(userMap.get(key));
|
|
|
+ }
|
|
|
+ sheetDataList.add(listSheet);
|
|
|
+ }
|
|
|
+ //当前时间
|
|
|
+ Date time = new Date();
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMddHHmmss");
|
|
|
+ ExcelUtils.export(response, "入库流水数据导出" + sdf.format(time), sheetDataList);
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 入库单生成
|
|
|
* @return
|
|
@@ -330,7 +513,20 @@ public class WarehousingServiceImpl implements WarehousingService {
|
|
|
return (stringBuilder.append(count + 1)).toString();
|
|
|
}
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 出库单id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String codeGenerateCk(){
|
|
|
+ StringBuilder stringBuilder = new StringBuilder("CK");
|
|
|
+ Date date = new Date();
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd");
|
|
|
+ stringBuilder.append(sdf.format(date));
|
|
|
+ int count = askGoodsMapper.getReturnRemovalCount();
|
|
|
+ for(int i = 0; i < 4 - (count + "").length(); i++){
|
|
|
+ stringBuilder.append("0");
|
|
|
+ }
|
|
|
+ return (stringBuilder.append(count + 1)).toString();
|
|
|
}
|
|
|
+
|
|
|
}
|