Commit 1e042cab LN

增加通用盘点模块

1 个父辈 adc459c3
正在显示 20 个修改的文件 包含 882 行增加1 行删除
...@@ -201,7 +201,10 @@ public class MenuInit { ...@@ -201,7 +201,10 @@ public class MenuInit {
Menu pMenuUser = Menu.CreatePMenu("用户管理", 11, "userManager", "Steve-Jobs", null); Menu pMenuUser = Menu.CreatePMenu("用户管理", 11, "userManager", "Steve-Jobs", null);
addDefaultFunctionMenu(111, pMenuUser,"用户管理", "peoples", "system/user/index", "peoples",DEFAULT_SHOW_MENU); addDefaultFunctionMenu(111, pMenuUser,"用户管理", "peoples", "system/user/index", "peoples",DEFAULT_SHOW_MENU);
addDefaultFunctionMenu(112, pMenuUser,"角色管理", "role", "system/role/index", "role",DEFAULT_SHOW_MENU); addDefaultFunctionMenu(112, pMenuUser,"角色管理", "role", "system/role/index", "role",DEFAULT_SHOW_MENU);
//条形码:条码管理,条码设置
Menu selfAudit = Menu.CreatePMenu("盘点管理", 12, "selfAuditManagerment", "selfAuditM",null);
addDefaultFunctionMenu(121,selfAudit, "盘点", "selfAudit", "system/selfAudit/index","selfAudit");
addDefaultFunctionMenu(122, selfAudit, "盘点记录","selfAuditLog", "system/selfAuditLog/index", "selfAuditLog");
Menu helpAbout = Menu.CreatePMenu("帮助", 9999, "help", "help",null); Menu helpAbout = Menu.CreatePMenu("帮助", 9999, "help", "help",null);
addDefaultFunctionMenu(99991, helpAbout, "说明书", "instruction", "system/instruction/index","aboutBook"); addDefaultFunctionMenu(99991, helpAbout, "说明书", "instruction", "system/instruction/index","aboutBook");
......
...@@ -158,4 +158,9 @@ public class Constants { ...@@ -158,4 +158,9 @@ public class Constants {
* 上次自动存档时间 * 上次自动存档时间
*/ */
public static final String LAST_BACKUP_TIME_KEY = "db.backup.lastTime"; public static final String LAST_BACKUP_TIME_KEY = "db.backup.lastTime";
/**
* 当前盘点的批次号
*/
public static final String CACHE_SELFAUDIT_BATCHNO="CACHE_selfAudit_batchNo";
} }
package com.neotel.smfcore.core.selfAudit.enums;
public enum SELFAUDIT_STATUS {
NEW,
/**
* 执行中
*/
EXECUTING,
/**
* 暂停
*/
PAUSE,
/**
* 已完成,任务全部完成
*/
FINISHED,
/**
* 已结束,未完成手动结束
*/
END;
}
package com.neotel.smfcore.core.selfAudit.rest;
import cn.hutool.core.util.ObjectUtil;
import com.neotel.smfcore.common.bean.PageData;
import com.neotel.smfcore.common.bean.ResultBean;
import com.neotel.smfcore.common.exception.ValidateException;
import com.neotel.smfcore.common.utils.Constants;
import com.neotel.smfcore.common.utils.QueryHelp;
import com.neotel.smfcore.core.device.util.DataCache;
import com.neotel.smfcore.core.materialLog.rest.query.MaterialLogCriteria;
import com.neotel.smfcore.core.selfAudit.enums.SELFAUDIT_STATUS;
import com.neotel.smfcore.core.selfAudit.rest.dto.SelfAuditDto;
import com.neotel.smfcore.core.selfAudit.rest.dto.SelfAuditItemDto;
import com.neotel.smfcore.core.selfAudit.rest.mapstruct.SelfAuditItemMapper;
import com.neotel.smfcore.core.selfAudit.rest.mapstruct.SelfAuditMapper;
import com.neotel.smfcore.core.selfAudit.service.manager.ISelfAuditManager;
import com.neotel.smfcore.core.selfAudit.service.po.SelfAudit;
import com.neotel.smfcore.core.selfAudit.service.po.SelfAuditItem;
import com.neotel.smfcore.core.selfAudit.util.SelfAuditUtil;
import com.neotel.smfcore.core.storage.service.manager.IStoragePosManager;
import com.neotel.smfcore.core.storage.service.po.Storage;
import com.neotel.smfcore.core.storage.service.po.StoragePos;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Slf4j
@Api(tags = "盘点")
@RestController
@RequestMapping("/api/selfAudit")
@RequiredArgsConstructor
public class SelfAuditController {
@Autowired
private ISelfAuditManager selfAuditManager;
@Autowired
private SelfAuditMapper selfAuditMapper;
@Autowired
private SelfAuditItemMapper selfAuditItemMapper;
@Autowired
private IStoragePosManager storagePosManager;
@Autowired
private DataCache dataCache;
@ApiOperation("开始盘点")
@PostMapping(value = "/start")
public ResultBean start(@RequestBody Map<String, Object> mapValues) {
//上一次盘点是否完成
String batchNo = dataCache.getCache(Constants.CACHE_SELFAUDIT_BATCHNO);
if (ObjectUtil.isNotEmpty(batchNo)) {
SelfAudit selfAudit = selfAuditManager.findByBatchNo(batchNo);
if (selfAudit.getStatus().equals(SELFAUDIT_STATUS.END) || selfAudit.getStatus().equals(SELFAUDIT_STATUS.FINISHED)) {
} else {
ResultBean.newErrorResult(99, "smfcore.selfAudit.preNotEnd", "上次盘点{0}还未完成", new String[]{batchNo});
}
}
log.info("从dataCache删除已完成的盘点批次号:" + batchNo + " ");
dataCache.updateCache(Constants.CACHE_SELFAUDIT_BATCHNO, "");
//开始新的盘点
String[] storageIds = (String[]) mapValues.get("storageIds");
if (storageIds == null || storageIds.length <= 0) {
ResultBean.newErrorResult(99, "smfcore.selfAudit.noStorage", "请选择要盘点的设备");
}
List<SelfAuditItem> items=new ArrayList<>();
List<String> storageIdList=new ArrayList<>();
// List<StoragePos> allPosList=new ArrayList<>();
String no = SelfAuditUtil.createBatchNo();
for (String id :
storageIds) {
Storage storage=dataCache.getStorageById(id);
if(storage!=null){
List<StoragePos> posList=storagePosManager.findByQuery(new Query(Criteria.where("storageId").is(id)));
if(posList.size()>0){
// allPosList.addAll(posList);
storageIdList.add(id);
for (StoragePos pos :posList
) {
SelfAuditItem item = SelfAuditItem.newItem(no,storage.getCid(), pos);
items.add(item);
}
}
}
}
SelfAudit audit = new SelfAudit(no, SELFAUDIT_STATUS.NEW.name(), items.size(),0,storageIdList,new ArrayList<>() );
log.info("开始盘点: 批次号["+no+"] 设备ID["+String.join( ",",storageIdList)+"] 盘点库位数量:["+items.size()+"] ");
audit= selfAuditManager.createSelfAudit(audit,items);
SelfAuditDto dto=selfAuditMapper.toDto(audit);
//更新缓存
SelfAuditUtil.updateShelfAudit(audit);
return ResultBean.newOkResult(dto);
}
@ApiOperation("暂停盘点")
@PostMapping(value = "/pause")
public ResultBean pause(@RequestBody Map<String, String> mapValues) {
String batchNo=mapValues.get("batchNo");
SelfAudit selfAudit =getInfoByBatchNo(batchNo);
//结束盘点
log.info("手动暂停盘点,批次号:"+batchNo);
selfAudit.setStatus(SELFAUDIT_STATUS.PAUSE.name());
selfAuditManager.save(selfAudit);
//更新缓存
SelfAuditUtil.updateShelfAudit(selfAudit);
return ResultBean.newOkResult("OK");
}
@ApiOperation("结束盘点")
@PostMapping(value = "/finish")
public ResultBean finish(@RequestBody Map<String, String> mapValues) {
String batchNo=mapValues.get("batchNo");
SelfAudit selfAudit =getInfoByBatchNo(batchNo);
//结束盘点
log.info("手动结束盘点,批次号:"+batchNo);
selfAudit.setStatus(SELFAUDIT_STATUS.END.name());
selfAuditManager.save(selfAudit);
//清空dataCache
log.info("手动结束盘点,批次号:"+batchNo+" 完成,从dataCache删除批次号");
dataCache.updateCache(Constants.CACHE_SELFAUDIT_BATCHNO,"");
//更新缓存
SelfAuditUtil.updateShelfAudit(selfAudit);
return ResultBean.newOkResult("OK");
}
private SelfAudit getInfoByBatchNo(String batchNo) {
if (ObjectUtil.isEmpty(batchNo)) {
throw new ValidateException("smfcore.valueNotExist", "{0}[{1}]不存在", new String[]{"batchNo", batchNo});
}
SelfAudit selfAudit = SelfAuditUtil.getSelfAudit(batchNo);
if (selfAudit == null) {
selfAudit = selfAuditManager.findByBatchNo(batchNo);
}
if (selfAudit == null) {
throw new ValidateException("smfcore.selfAudit.notExist", "未找到批次号[{0}]的盘点信息", new String[]{batchNo});
}
if (selfAudit.getStatus().equals(SELFAUDIT_STATUS.END) || selfAudit.getStatus().equals(SELFAUDIT_STATUS.FINISHED)) {
//如果已完成
throw new ValidateException("smfcore.selfAudit.hasEnd", "[{0}]盘点已完成", new String[]{batchNo});
}
return selfAudit;
}
@ApiOperation("获取实时盘点信息")
@GetMapping(value = "/info")
public SelfAuditDto info( ) {
//获取当前的盘点信息
String batchNo = dataCache.getCache(Constants.CACHE_SELFAUDIT_BATCHNO);
if (ObjectUtil.isNotEmpty(batchNo)) {
SelfAudit selfAudit = SelfAuditUtil.getSelfAudit(batchNo);
if (selfAudit == null) {
selfAudit = selfAuditManager.findByBatchNo(batchNo);
}
if (selfAudit != null) {
return toSelfAuditDto(selfAudit);
}
}
//暂无盘点信息
return null;
}
@ApiOperation("查询盘点日志")
@GetMapping(value = "/list")
public PageData<SelfAuditDto> queryList(MaterialLogCriteria criteria, Pageable pageable) {
Query query = QueryHelp.getQuery(criteria);
PageData<SelfAudit> pages = selfAuditManager.findByPage(query, pageable);
List<SelfAuditDto> logDtos = selfAuditMapper.toDto(pages.getContent());
return new PageData(logDtos, pages.getTotalElements());
}
@ApiOperation("盘点详情")
@GetMapping("/detial")
public SelfAuditDto detial(@RequestParam(required = false) String id, @RequestParam(required = false) String batchNo) {
if (!ObjectUtils.isEmpty(id)) {
SelfAudit selfAudit = selfAuditManager.get(id);
if (selfAudit != null) {
return toSelfAuditDto(selfAudit);
}
} else if (!ObjectUtils.isEmpty(batchNo)) {
SelfAudit selfAudit = selfAuditManager.findByBatchNo(batchNo);
if (selfAudit != null) {
return toSelfAuditDto(selfAudit);
}
}
throw new ValidateException("smfcore.valueCanotNull", "{0}不能为空", new String[]{"batchNo"});
}
private SelfAuditDto toSelfAuditDto(SelfAudit selfAudit) {
SelfAuditDto dto = selfAuditMapper.toDto(selfAudit);
List<SelfAuditItem> selfAuditItemDtos = selfAudit.getItems();
List<SelfAuditItemDto> dtos = selfAuditItemMapper.toDto(selfAuditItemDtos);
dto.setItems(dtos);
return dto;
}
}
package com.neotel.smfcore.core.selfAudit.rest;
import cn.hutool.core.util.ObjectUtil;
import com.neotel.smfcore.common.bean.ResultBean;
import com.neotel.smfcore.common.exception.ValidateException;
import com.neotel.smfcore.common.utils.Constants;
import com.neotel.smfcore.core.barcode.service.po.Barcode;
import com.neotel.smfcore.core.device.util.DataCache;
import com.neotel.smfcore.core.selfAudit.service.manager.ISelfAuditItemManager;
import com.neotel.smfcore.core.selfAudit.service.manager.ISelfAuditManager;
import com.neotel.smfcore.core.selfAudit.service.po.SelfAudit;
import com.neotel.smfcore.core.selfAudit.service.po.SelfAuditItem;
import com.neotel.smfcore.core.selfAudit.util.SelfAuditUtil;
import com.neotel.smfcore.core.storage.service.manager.IStoragePosManager;
import com.neotel.smfcore.core.storage.service.po.Storage;
import com.neotel.smfcore.core.storage.service.po.StoragePos;
import com.neotel.smfcore.core.system.util.TaskService;
import com.neotel.smfcore.security.annotation.AnonymousAccess;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@RestController
@Api(tags = "盘点功能,设备端调用")
@RequestMapping("/rest/selfAudit")
public class SelfAuditDeviceController {
@Autowired
private DataCache dataCache;
@Autowired
private ISelfAuditManager selfAuditManager;
@Autowired
private IStoragePosManager storagePosManager;
@Autowired
private TaskService taskService;
@Autowired
private ISelfAuditItemManager selfAuditItemManager;
private SelfAudit getCurrObj(){
//获取当前的盘点信息
String batchNo = dataCache.getCache(Constants.CACHE_SELFAUDIT_BATCHNO);
if (ObjectUtil.isNotEmpty(batchNo)) {
SelfAudit selfAudit = SelfAuditUtil.getSelfAudit(batchNo);
if (selfAudit == null) {
selfAudit = selfAuditManager.findByBatchNo(batchNo);
}
return selfAudit;
}
return null;
}
@ApiOperation("盘点: 根据cid下一个盘点库位号 ")
@PostMapping(value = "/getNetPos")
@ResponseBody
@AnonymousAccess
public ResultBean getNetPos(HttpServletRequest request) {
SelfAudit selfAudit=getCurrObj();
if(selfAudit==null){
return ResultBean.newErrorResult(99,"smfcore.selfAudit.notFind","未找到盘点信息");
}
String cid = request.getParameter("cid");
//根据CID 查找下一个
List<SelfAuditItem> items=selfAudit.getItems();
for (SelfAuditItem item :
items) {
if (item.getCid().equals(cid) && item.getItemStatus() == 0) {
//返回此库位号
Map<String,String> resultMap=new HashMap<>();
resultMap.put("posName",item.getPosName());
resultMap.put("barcode",item.getBarcode());
resultMap.put("batchNo",item.getBatchNo());
log.info("cid=["+cid+"]获取盘点["+selfAudit.getBatchNo()+"]下一个库位成功:posName["+item.getPosName()+"]barcode["+item.getBarcode()+"]");
return ResultBean.newOkResult(resultMap);
}
}
//根据CID获取盘点的下一个库位
return ResultBean.newOkResult("ok");
}
@ApiOperation("盘点: 库位已出库完成 ")
@PostMapping(value = "/posOutEnd")
@ResponseBody
@AnonymousAccess
public ResultBean PosOutEnd(HttpServletRequest request) {
String posName = request.getParameter("posName");
log.info("盘点:posOutEnd:posName=["+posName+"]");
//发送库位号
//指定库位出库完成,清空库位信息(自动生成一条出库任务并结束)
SelfAudit selfAudit=getCurrObj();
if(selfAudit==null){
log.error("盘点:posOutEnd:posName=["+posName+"]:未找到盘点信息");
return ResultBean.newErrorResult(99,"smfcore.selfAudit.notFind","未找到盘点信息");
}
List<SelfAuditItem> items=selfAudit.getItems();
List<SelfAuditItem> newItems=new ArrayList<>();
boolean findOk=false;
for (SelfAuditItem item :
items) {
if (item.getPosName().equals(posName)) {
log.info(" 盘点["+selfAudit.getBatchNo()+"]库位出库成功:posName["+item.getPosName()+"]barcode["+item.getBarcode()+"],自动生成出库任务,清空库位");
StoragePos storagePos = storagePosManager.getByPosName(posName);
if (storagePos != null) {
try {
log.info("盘点完成,开始清空库位[" + storagePos.getPosName() + "]");
Barcode barcode = storagePos.getBarcode();
if (barcode != null) {
log.info("盘点完成,清理库位[" + storagePos.getPosName() + "]中的库存" + barcode.getBarcode());
String opUser = "SelfAudit";
log.info(opUser + "盘点完成,清理库位[" + storagePos.getPosName() + "]中的库存" + barcode.getBarcode());
taskService.addTaskToFinished(storagePos, null, opUser + "-clear");
Storage storage = dataCache.getStorageById(storagePos.getStorageId());
dataCache.reloadStorage(storage, storage.getCid());
}
//更新状态
} catch (Exception e) {
throw new ValidateException("smfcore.error", "出错{0}", new String[]{e.toString()});
}
}
item.setItemStatus(1);
selfAuditItemManager.save(item);
}
newItems.add(item);
}
if(findOk){
selfAudit.setItems(newItems);
SelfAuditUtil.updateShelfAudit(selfAudit);
return ResultBean.newOkResult("ok");
}
log.error("盘点:posOutEnd:posName=["+posName+"]:未找到库位的盘点信息");
return ResultBean.newErrorResult(99,"smfcore.selfAudit.posNotFind","未找到库位[{0}]的盘点信息");
}
@ApiOperation("盘点: 库位盘点完成 ")
@PostMapping(value = "/posSelfAuditEnd")
@ResponseBody
@AnonymousAccess
public ResultBean PosSelfAuditEnd(HttpServletRequest request) {
String posName = request.getParameter("posName");
String barcode = request.getParameter("barcode");
String actualBarcode = request.getParameter("actualBarcode");
log.info("盘点:posSelfAuditEnd:posName=[" + posName + "],barcode=[" + barcode + "],actualBarcode=[" + actualBarcode + "]");
//发送库位号,库存条码,实时条码
SelfAudit selfAudit = getCurrObj();
if (selfAudit == null) {
log.info("盘点:posSelfAuditEnd:posName=[" + posName + "],barcode=[" + barcode + "],actualBarcode=[" + actualBarcode + "]:未找到盘点信息");
return ResultBean.newErrorResult(99, "smfcore.selfAudit.notFind", "未找到盘点信息");
}
List<SelfAuditItem> items = selfAudit.getItems();
List<SelfAuditItem> newItems = new ArrayList<>();
boolean findOk = false;
for (SelfAuditItem item :
items) {
if (item.getPosName().equals(posName)) {
log.info(" 盘点[" + selfAudit.getBatchNo() + "]库位入库完成:posName[" + item.getPosName() + "]barcode[" + item.getBarcode() + "],actualBarcode=[" + actualBarcode + "]");
StoragePos storagePos = storagePosManager.getByPosName(posName);
if (storagePos != null) {
try {
log.info("盘点入库完成,自动生成入库任务,更新库位[" + storagePos.getPosName() + "]");
//TODO
} catch (Exception e) {
throw new ValidateException("smfcore.error", "出错{0}", new String[]{e.toString()});
}
}
item.setItemStatus(2);
selfAuditItemManager.save(item);
}
newItems.add(item);
}
if (findOk) {
selfAudit.setItems(newItems);
SelfAuditUtil.updateShelfAudit(selfAudit);
return ResultBean.newOkResult("ok");
}
log.info("盘点:posSelfAuditEnd:posName=[" + posName + "],barcode=[" + barcode + "],actualBarcode=[" + actualBarcode + "]:未找到库位的盘点信息");
return ResultBean.newErrorResult(99, "smfcore.selfAudit.posNotFind", "未找到库位[{0}]的盘点信息");
}
}
package com.neotel.smfcore.core.selfAudit.rest.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Transient;
import java.io.Serializable;
import java.util.List;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class SelfAuditDto implements Serializable {
@ApiModelProperty("批次号")
private String batchNo;
@ApiModelProperty("状态")
private String status;
@ApiModelProperty("总库位数")
private Integer totalItemNum;
@ApiModelProperty("已结束库位数")
private Integer endItemNum;
@Transient
private List<SelfAuditItemDto> items;
}
package com.neotel.smfcore.core.selfAudit.rest.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class SelfAuditItemDto implements Serializable {
@ApiModelProperty("批次号")
private String BatchNo;
@ApiModelProperty("库位号(数据库ID)")
private String posId;
@ApiModelProperty("料仓CID")
private String cid;
@ApiModelProperty("库位号名称")
private String posName;
@ApiModelProperty("库存条码")
private String barcode;
@ApiModelProperty("实际条码")
private String actualBarcode;
}
package com.neotel.smfcore.core.selfAudit.rest.mapstruct;
import com.neotel.smfcore.common.base.BaseMapper;
import com.neotel.smfcore.core.selfAudit.rest.dto.SelfAuditItemDto;
import com.neotel.smfcore.core.selfAudit.service.po.SelfAuditItem;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
@Mapper(componentModel = "spring",unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface SelfAuditItemMapper extends BaseMapper<SelfAuditItemDto, SelfAuditItem> {
}
package com.neotel.smfcore.core.selfAudit.rest.mapstruct;
import com.neotel.smfcore.common.base.BaseMapper;
import com.neotel.smfcore.core.selfAudit.rest.dto.SelfAuditDto;
import com.neotel.smfcore.core.selfAudit.service.po.SelfAudit;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
@Mapper(componentModel = "spring",unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface SelfAuditMapper extends BaseMapper<SelfAuditDto, SelfAudit> {
}
package com.neotel.smfcore.core.selfAudit.service.dao;
import com.neotel.smfcore.common.base.IBaseDao;
public interface ISelfAuditDao extends IBaseDao {
}
package com.neotel.smfcore.core.selfAudit.service.dao;
import com.neotel.smfcore.common.base.IBaseDao;
public interface ISelfAuditItemDao extends IBaseDao {
}
package com.neotel.smfcore.core.selfAudit.service.dao.impl;
import com.neotel.smfcore.common.base.AbstractBaseDao;
import com.neotel.smfcore.core.selfAudit.service.dao.ISelfAuditDao;
import com.neotel.smfcore.core.selfAudit.service.po.SelfAudit;
import org.springframework.stereotype.Service;
@Service
public class SelfAuditDao extends AbstractBaseDao implements ISelfAuditDao {
@Override
public Class getEntityClass() {
return SelfAudit.class;
}
}
package com.neotel.smfcore.core.selfAudit.service.dao.impl;
import com.neotel.smfcore.common.base.AbstractBaseDao;
import com.neotel.smfcore.core.selfAudit.service.dao.ISelfAuditItemDao;
import com.neotel.smfcore.core.selfAudit.service.po.SelfAuditItem;
import org.springframework.stereotype.Service;
@Service
public class SelfAuditItemDao extends AbstractBaseDao implements ISelfAuditItemDao {
@Override
public Class getEntityClass() {
return SelfAuditItem.class;
}
}
package com.neotel.smfcore.core.selfAudit.service.manager;
import com.neotel.smfcore.common.base.IBaseManager;
import com.neotel.smfcore.core.selfAudit.service.po.SelfAuditItem;
import java.util.List;
public interface ISelfAuditItemManager extends IBaseManager<SelfAuditItem> {
public List<SelfAuditItem> getItemsByBatchNo(String batchNo);
public List<SelfAuditItem> getItemsBySelfAuditId(String selfAuditId);
}
package com.neotel.smfcore.core.selfAudit.service.manager;
import com.neotel.smfcore.common.base.IBaseManager;
import com.neotel.smfcore.core.selfAudit.service.po.SelfAudit;
import com.neotel.smfcore.core.selfAudit.service.po.SelfAuditItem;
import java.util.List;
public interface ISelfAuditManager extends IBaseManager<SelfAudit> {
public SelfAudit findByBatchNo(String batchNo);
public SelfAudit createSelfAudit(SelfAudit selfAudit, List<SelfAuditItem> items);
}
package com.neotel.smfcore.core.selfAudit.service.manager.impl;
import com.neotel.smfcore.common.bean.PageData;
import com.neotel.smfcore.common.exception.ValidateException;
import com.neotel.smfcore.core.selfAudit.service.dao.ISelfAuditItemDao;
import com.neotel.smfcore.core.selfAudit.service.manager.ISelfAuditItemManager;
import com.neotel.smfcore.core.selfAudit.service.po.SelfAuditItem;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class SelfAuditItemManager implements ISelfAuditItemManager {
private ISelfAuditItemDao selfAuditItemDao;
@Override
public SelfAuditItem get(String id) {
return selfAuditItemDao.findOneById(id);
}
@Override
public SelfAuditItem save(SelfAuditItem object) throws ValidateException {
return selfAuditItemDao.save(object);
}
@Override
public void delete(SelfAuditItem object) throws ValidateException {
selfAuditItemDao.removeOneById(object.getId());
}
@Override
public PageData<SelfAuditItem> findByPage(Query query, Pageable pageable) {
int totalCount = selfAuditItemDao.countByQuery(query);
List<SelfAuditItem> barcodes = selfAuditItemDao.findByQuery(query, pageable);
return new PageData(barcodes, totalCount);
}
@Override
public List<SelfAuditItem> findByQuery(Query query) {
return selfAuditItemDao.findByQuery(query);
}
@Override
public List<SelfAuditItem> getItemsByBatchNo(String batchNo) {
return selfAuditItemDao.findListByCondition("batchNo", batchNo);
}
@Override
public List<SelfAuditItem> getItemsBySelfAuditId(String selfAuditId) {
return selfAuditItemDao.findListByCondition("selfAuditId", selfAuditId);
}
}
package com.neotel.smfcore.core.selfAudit.service.manager.impl;
import com.neotel.smfcore.common.bean.PageData;
import com.neotel.smfcore.common.exception.ValidateException;
import com.neotel.smfcore.core.selfAudit.service.dao.ISelfAuditDao;
import com.neotel.smfcore.core.selfAudit.service.dao.ISelfAuditItemDao;
import com.neotel.smfcore.core.selfAudit.service.manager.ISelfAuditManager;
import com.neotel.smfcore.core.selfAudit.service.po.SelfAudit;
import com.neotel.smfcore.core.selfAudit.service.po.SelfAuditItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class SelfAuditManager implements ISelfAuditManager {
@Autowired
private ISelfAuditDao selfAuditDao;
@Autowired
private ISelfAuditItemDao selfAuditItemDao;
@Override
public SelfAudit get(String id) {
SelfAudit selfAudit= selfAuditDao.findOneById(id);
if(selfAudit!=null){
List<SelfAuditItem> items=selfAuditItemDao.findListByCondition("selfAuditId",selfAudit.getId());
selfAudit.setItems(items);
}
return selfAudit;
}
@Override
public SelfAudit save(SelfAudit object) throws ValidateException {
return selfAuditDao.save(object);
}
@Override
public void delete(SelfAudit object) throws ValidateException {
selfAuditDao.removeOneById(object.getId());
}
@Override
public PageData<SelfAudit> findByPage(Query query, Pageable pageable) {
int totalCount = selfAuditDao.countByQuery(query);
List<SelfAudit> barcodes = selfAuditDao.findByQuery(query, pageable);
return new PageData(barcodes, totalCount);
}
@Override
public List<SelfAudit> findByQuery(Query query) {
return selfAuditDao.findByQuery(query);
}
@Override
public SelfAudit findByBatchNo(String batchNo) {
Query query = new Query(Criteria.where("batchNo").is(batchNo));
SelfAudit selfAudit = selfAuditDao.findOne(query);
if (selfAudit != null) {
List<SelfAuditItem> items = selfAuditItemDao.findListByCondition("selfAuditId",selfAudit.getId());
selfAudit.setItems(items);
}
return selfAudit;
}
@Override
public SelfAudit createSelfAudit(SelfAudit selfAudit, List<SelfAuditItem> items) {
selfAudit=save(selfAudit) ;
for (int i=0;i<items.size();i++){
items.get(i).setSelfAuditId(selfAudit.getId());
}
//批量插入
selfAuditDao.insertAll(items);
selfAudit.setItems(items);
return selfAudit;
}
}
package com.neotel.smfcore.core.selfAudit.service.po;
import com.neotel.smfcore.common.base.BasePo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.mapping.Document;
import java.io.Serializable;
import java.util.List;
@Data
@Document
@AllArgsConstructor
@NoArgsConstructor
public class SelfAudit extends BasePo implements Serializable {
/**
*批次号
*/
private String batchNo;
/**
* 状态
*/
private String status;
/**
* 总库位数
*/
private Integer totalItemNum;
/**
* 已结束库位数
*/
private Integer endItemNum;
/**
* 盘点选择的料仓ID列表
*/
private List<String> storageIds;
@Transient
private List<SelfAuditItem> items;
}
package com.neotel.smfcore.core.selfAudit.service.po;
import com.neotel.smfcore.common.base.BasePo;
import com.neotel.smfcore.core.storage.service.po.StoragePos;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.mongodb.core.mapping.Document;
import java.io.Serializable;
@Data
@Document
@AllArgsConstructor
@NoArgsConstructor
public class SelfAuditItem extends BasePo implements Serializable {
private String selfAuditId;
/**
*批次号
*/
private String batchNo;
/**
* 库位号(数据库ID)
*/
private String posId;
/**
*料仓数据库ID
*/
private String storageId;
/**
* 料仓CID
*/
private String cid;
/**
*库位号名称
*/
private String posName;
/**
*库存条码
*/
private String barcode;
/**
*实际条码
*/
private String actualBarcode;
/**
* 盘点状态 0=等待中,1=出库完成,2=盘点完成
*/
private int itemStatus=0;
public static SelfAuditItem newItem(String cid, String batchNo, StoragePos pos){
SelfAuditItem item=new SelfAuditItem();
item.setCid(cid);
item.setBarcode(batchNo);
item.setPosId(pos.getId());
item.setPosName(pos.getPosName());
item.setStorageId(pos.getStorageId());
if(pos.getBarcode().getBarcode()!=null) {
item.setBarcode(pos.getBarcode().getBarcode());
}else{
item.setBarcode("");
}
item.setActualBarcode("");
return item;
}
}
package com.neotel.smfcore.core.selfAudit.util;
import com.neotel.smfcore.common.utils.DateUtil;
import com.neotel.smfcore.core.selfAudit.service.po.SelfAudit;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class SelfAuditUtil {
public static String createBatchNo() {
Date date = new Date();
String dateStr = DateUtil.toDateString(date, "yyyyMMddHHmm");
return "NO" + dateStr;
}
private static Map<String, SelfAudit> selfAuditMap=new ConcurrentHashMap<>();
public static SelfAudit getSelfAudit(String batchNo){
if(selfAuditMap==null){
selfAuditMap=new HashMap<>();
}
return selfAuditMap.get(batchNo);
}
public static void updateShelfAudit(SelfAudit selfAudit){
selfAuditMap.put(selfAudit.getBatchNo(),selfAudit);
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!