【生产领料】 数据同步用友

dev
siontion 3 months ago
parent 2587ce307b
commit 1fd3d86e83

@ -76,6 +76,7 @@ public interface ErrorCodeConstants {
ErrorCode STORAGE_STOCK_QUANTITY_LACK = new ErrorCode(1_003_009, "库存数量不足");
ErrorCode TPLUS_LASTEST_STOCK_NOT_EXISTS = new ErrorCode(1_003_010, "用友Tplus最新库存不存在");
ErrorCode TPLUS_LASTEST_BOM_NOT_EXISTS = new ErrorCode(1_003_011, "用友Tplus最新BOM不存在");
ErrorCode TPLUS_STORAGE_OUT_NOT_EXISTS = new ErrorCode(1_003_012, "用友生产领料不存在");
/************订单管理***********/
ErrorCode PROJECT_ORDER_NOT_EXISTS = new ErrorCode(1_004_001, "项目订单不存在");

@ -257,4 +257,10 @@ public class ChanjetController {
//创建入库
chanjetSchedule.createStorageInOrder();
}
@Scheduled(cron = "0 0 2 * * ?")
public void synchronizeData2() throws ChanjetApiException{
//查询库存-现存量
chanjetSchedule.createStorageOut();
}
}

@ -0,0 +1,95 @@
package com.chanko.yunxi.mes.module.biz.controller.admin.tplusstorageout;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;
import com.chanko.yunxi.mes.framework.common.pojo.PageParam;
import com.chanko.yunxi.mes.framework.common.pojo.PageResult;
import com.chanko.yunxi.mes.framework.common.pojo.CommonResult;
import com.chanko.yunxi.mes.framework.common.util.object.BeanUtils;
import static com.chanko.yunxi.mes.framework.common.pojo.CommonResult.success;
import com.chanko.yunxi.mes.framework.excel.core.util.ExcelUtils;
import com.chanko.yunxi.mes.framework.operatelog.core.annotations.OperateLog;
import static com.chanko.yunxi.mes.framework.operatelog.core.enums.OperateTypeEnum.*;
import com.chanko.yunxi.mes.module.biz.controller.admin.tplusstorageout.vo.*;
import com.chanko.yunxi.mes.module.biz.dal.dataobject.tplusstorageout.TplusStorageOutDO;
import com.chanko.yunxi.mes.module.biz.service.tplusstorageout.TplusStorageOutService;
@Tag(name = "管理后台 - 用友生产领料")
@RestController
@RequestMapping("/biz/tplus-storage-out")
@Validated
public class TplusStorageOutController {
@Resource
private TplusStorageOutService tplusStorageOutService;
@PostMapping("/create")
@Operation(summary = "创建用友生产领料")
@PreAuthorize("@ss.hasPermission('biz:tplus-storage-out:create')")
public CommonResult<Long> createTplusStorageOut(@Valid @RequestBody TplusStorageOutSaveReqVO createReqVO) {
return success(tplusStorageOutService.createTplusStorageOut(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新用友生产领料")
@PreAuthorize("@ss.hasPermission('biz:tplus-storage-out:update')")
public CommonResult<Boolean> updateTplusStorageOut(@Valid @RequestBody TplusStorageOutSaveReqVO updateReqVO) {
tplusStorageOutService.updateTplusStorageOut(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除用友生产领料")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('biz:tplus-storage-out:delete')")
public CommonResult<Boolean> deleteTplusStorageOut(@RequestParam("id") Long id) {
tplusStorageOutService.deleteTplusStorageOut(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得用友生产领料")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('biz:tplus-storage-out:query')")
public CommonResult<TplusStorageOutRespVO> getTplusStorageOut(@RequestParam("id") Long id) {
TplusStorageOutDO tplusStorageOut = tplusStorageOutService.getTplusStorageOut(id);
return success(BeanUtils.toBean(tplusStorageOut, TplusStorageOutRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得用友生产领料分页")
@PreAuthorize("@ss.hasPermission('biz:tplus-storage-out:query')")
public CommonResult<PageResult<TplusStorageOutRespVO>> getTplusStorageOutPage(@Valid TplusStorageOutPageReqVO pageReqVO) {
PageResult<TplusStorageOutDO> pageResult = tplusStorageOutService.getTplusStorageOutPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, TplusStorageOutRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出用友生产领料 Excel")
@PreAuthorize("@ss.hasPermission('biz:tplus-storage-out:export')")
@OperateLog(type = EXPORT)
public void exportTplusStorageOutExcel(@Valid TplusStorageOutPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<TplusStorageOutDO> list = tplusStorageOutService.getTplusStorageOutPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "用友生产领料.xls", "数据", TplusStorageOutRespVO.class,
BeanUtils.toBean(list, TplusStorageOutRespVO.class));
}
}

@ -0,0 +1,44 @@
package com.chanko.yunxi.mes.module.biz.controller.admin.tplusstorageout.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import com.chanko.yunxi.mes.framework.common.pojo.PageParam;
import java.math.BigDecimal;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static com.chanko.yunxi.mes.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 用友生产领料分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class TplusStorageOutPageReqVO extends PageParam {
@Schema(description = "自增字段,唯一")
private Long id;
@Schema(description = "出库id")
private Long stockId;
@Schema(description = "领料数量")
private BigDecimal storageOkQty;
@Schema(description = "产品编码")
private String productCode;
@Schema(description = "物料编码")
private String projectSubCode;
@Schema(description = "工序id")
private Long procedureId;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
@Schema(description = "是否推送")
private Integer isSend;
}

@ -0,0 +1,49 @@
package com.chanko.yunxi.mes.module.biz.controller.admin.tplusstorageout.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import java.util.*;
import java.math.BigDecimal;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.*;
@Schema(description = "管理后台 - 用友生产领料 Response VO")
@Data
@ExcelIgnoreUnannotated
public class TplusStorageOutRespVO {
@Schema(description = "自增字段,唯一", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("自增字段,唯一")
private Long id;
@Schema(description = "出库id")
@ExcelProperty("出库id")
private Long stockId;
@Schema(description = "领料数量")
@ExcelProperty("领料数量")
private BigDecimal storageOkQty;
@Schema(description = "产品编码")
@ExcelProperty("产品编码")
private String productCode;
@Schema(description = "物料编码")
@ExcelProperty("物料编码")
private String projectSubCode;
@Schema(description = "工序id")
@ExcelProperty("工序id")
private Long procedureId;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
@Schema(description = "是否推送")
@ExcelProperty("是否推送")
private Integer isSend;
}

@ -0,0 +1,35 @@
package com.chanko.yunxi.mes.module.biz.controller.admin.tplusstorageout.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import javax.validation.constraints.*;
import java.util.*;
import java.math.BigDecimal;
@Schema(description = "管理后台 - 用友生产领料新增/修改 Request VO")
@Data
public class TplusStorageOutSaveReqVO {
@Schema(description = "自增字段,唯一", requiredMode = Schema.RequiredMode.REQUIRED)
private Long id;
@Schema(description = "出库id")
private Long stockId;
@Schema(description = "领料数量")
private BigDecimal storageOkQty;
@Schema(description = "产品编码")
private String productCode;
@Schema(description = "物料编码")
private String projectSubCode;
@Schema(description = "工序id")
private Long procedureId;
@Schema(description = "是否推送")
private Integer isSend;
}

@ -118,4 +118,13 @@ public class TplusLastestBomDO extends BaseDO {
@TableField(exist = false)
private Long matId;
@TableField(exist = false)
private Long stockId;
@TableField(exist = false)
private BigDecimal storageOkQty;
@TableField(exist = false)
private Long procedureId;
}

@ -0,0 +1,56 @@
package com.chanko.yunxi.mes.module.biz.dal.dataobject.tplusstorageout;
import lombok.*;
import java.util.*;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import com.chanko.yunxi.mes.framework.mybatis.core.dataobject.BaseDO;
/**
* DO
*
* @author
*/
@TableName("tplus_storage_out")
@KeySequence("tplus_storage_out_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class TplusStorageOutDO extends BaseDO {
/**
*
*/
@TableId
private Long id;
/**
* id
*/
private Long stockId;
/**
*
*/
private BigDecimal storageOkQty;
/**
*
*/
private String productCode;
/**
*
*/
private String projectSubCode;
/**
* id
*/
private Long procedureId;
/**
*
*/
private Integer isSend;
}

@ -65,5 +65,24 @@ public interface TplusLastestBomMapper extends BaseMapperX<TplusLastestBomDO> {
;
return selectPage(reqVO,query);
}
default List<TplusLastestBomDO> selectListByStockId(List<String> codes, Long stockId) {
String inCodes = "";
codes.forEach(so->{
so ="'"+so+"'";
});
inCodes = String.join(",",codes);
MPJLambdaWrapper<TplusLastestBomDO> query = new MPJLambdaWrapper<>();
query.distinct()
.select(stockId+" as stock_id")
.select("ifnull((select storage_ok_qty from wms_storage_mat where stock_id="+stockId+" and mat_id in (select id from base_material where code=t.project_sub_code) ),0)*(t.required_quantity/t.produce_quantity)/(select sum(a.required_quantity/a.produce_quantity) from tplus_lastest_bom as a where a.project_sub_code=t.project_sub_code and a.top_code in ("+inCodes+") and a.deleted=0 and a.tenant_id=2) as storage_ok_qty")
.select("t.top_code,t.project_sub_code")
.select("(select procedure_id from wms_storage_mat where stock_id="+stockId+" and mat_id in (select id from base_material where code=t.project_sub_code) ) as procedure_id")
.disableSubLogicDel()
.in(CollUtil.isNotEmpty(codes), TplusLastestBomDO::getTopCode, codes)
;
return selectList(query);
}
void updateTenantId();
}

@ -0,0 +1,33 @@
package com.chanko.yunxi.mes.module.biz.dal.mysql.tplusstorageout;
import java.util.*;
import com.chanko.yunxi.mes.framework.common.pojo.PageResult;
import com.chanko.yunxi.mes.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.chanko.yunxi.mes.framework.mybatis.core.mapper.BaseMapperX;
import com.chanko.yunxi.mes.module.biz.dal.dataobject.tplusstorageout.TplusStorageOutDO;
import org.apache.ibatis.annotations.Mapper;
import com.chanko.yunxi.mes.module.biz.controller.admin.tplusstorageout.vo.*;
/**
* Mapper
*
* @author
*/
@Mapper
public interface TplusStorageOutMapper extends BaseMapperX<TplusStorageOutDO> {
default PageResult<TplusStorageOutDO> selectPage(TplusStorageOutPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<TplusStorageOutDO>()
.eqIfPresent(TplusStorageOutDO::getId, reqVO.getId())
.eqIfPresent(TplusStorageOutDO::getStockId, reqVO.getStockId())
.eqIfPresent(TplusStorageOutDO::getStorageOkQty, reqVO.getStorageOkQty())
.eqIfPresent(TplusStorageOutDO::getProductCode, reqVO.getProductCode())
.eqIfPresent(TplusStorageOutDO::getProjectSubCode, reqVO.getProjectSubCode())
.eqIfPresent(TplusStorageOutDO::getProcedureId, reqVO.getProcedureId())
.betweenIfPresent(TplusStorageOutDO::getCreateTime, reqVO.getCreateTime())
.eqIfPresent(TplusStorageOutDO::getIsSend, reqVO.getIsSend())
.orderByDesc(TplusStorageOutDO::getId));
}
}

@ -37,6 +37,7 @@ import com.chanko.yunxi.mes.module.biz.dal.dataobject.taskdispatch.TaskDispatchD
import com.chanko.yunxi.mes.module.biz.dal.dataobject.taskreport.TaskReportDO;
import com.chanko.yunxi.mes.module.biz.dal.dataobject.tpluslastestbom.TplusLastestBomDO;
import com.chanko.yunxi.mes.module.biz.dal.dataobject.tpluslasteststock.TplusLastestStockDO;
import com.chanko.yunxi.mes.module.biz.dal.dataobject.tplusstorageout.TplusStorageOutDO;
import com.chanko.yunxi.mes.module.biz.dal.dataobject.warehouse.WarehouseDO;
import com.chanko.yunxi.mes.module.biz.dal.dataobject.workshop.WorkshopDO;
import com.chanko.yunxi.mes.module.biz.dal.mysql.customer.CustomerMapper;
@ -51,6 +52,7 @@ import com.chanko.yunxi.mes.module.biz.dal.mysql.taskdispatch.TaskDispatchDetail
import com.chanko.yunxi.mes.module.biz.dal.mysql.taskreport.TaskReportMapper;
import com.chanko.yunxi.mes.module.biz.dal.mysql.tpluslastestbom.TplusLastestBomMapper;
import com.chanko.yunxi.mes.module.biz.dal.mysql.tpluslasteststock.TplusLastestStockMapper;
import com.chanko.yunxi.mes.module.biz.dal.mysql.tplusstorageout.TplusStorageOutMapper;
import com.chanko.yunxi.mes.module.biz.dal.mysql.warehouse.WarehouseMapper;
import com.chanko.yunxi.mes.module.biz.dal.mysql.workshop.WorkshopMapper;
import com.chanko.yunxi.mes.module.biz.enums.*;
@ -157,6 +159,9 @@ public class ChanjetSchedule {
@Resource
private ChanjetManager chanjetManager;
@Resource
private TplusStorageOutMapper tplusStorageOutMapper;
private Boolean getSystemParameters(){
Boolean chanjet_switch = true;
return chanjet_switch;
@ -342,107 +347,6 @@ public class ChanjetSchedule {
}
/**
*
*
* @param materialDOList
* @param warehouseId
* @throws ChanjetApiException
*/
@Transactional(rollbackFor = Exception.class)
public void queryStockAndInject(List<MaterialDO> materialDOList, Long warehouseId) throws ChanjetApiException {
// 设置为“否”,关闭所有与用友通信的接口
if(!getSystemParameters()) return ;
CommonResult<List<QueryCurrentStockResVO>> result = chanjetSpi.invokeRetList(QUERY_CURRENT_STOCK,
new QueryCurrentStockReqVO(new QueryCurrentStockReqVO.QueryCurrentStockParamVO(materialDOList.stream().map(MaterialDO::getCode).collect(Collectors.toList()))),
QueryCurrentStockResVO.class);
if(!result.isSuccess()){
throw exception(CALL_API_ERROR);
}
List<QueryCurrentStockResVO> dataList = result.getData();
if(dataList == null) dataList = new ArrayList<>(16);
for (MaterialDO aDo : materialDOList) {
List<QueryCurrentStockResVO> stockResVOList = dataList.stream().filter(vo -> vo.getWarehouseID().longValue() == warehouseId.longValue() && aDo.getCode().equals(vo.getInventoryCode())).collect(Collectors.toList());
if(CollUtil.isEmpty(stockResVOList)){
aDo.setStockQuantity(new BigDecimal(0));
}else{
QueryCurrentStockResVO resVO = stockResVOList.get(0);
BigDecimal stockQuantity = new BigDecimal(resVO.getAvailableQuantity());;
if(warehouseId != null && resVO.getWarehouseID().longValue() != warehouseId.longValue()){
stockQuantity = new BigDecimal(0);
}
aDo.setStockQuantity(stockQuantity);
}
}
}
/**
*
*
* @param doList
* @param warehouseId
* @throws ChanjetApiException
*/
@Transactional(rollbackFor = Exception.class)
public void queryStockAndInject2(List<StorageMatDO> doList, Long warehouseId) throws ChanjetApiException {
// 设置为“否”,关闭所有与用友通信的接口
if(!getSystemParameters()) return;
CommonResult<List<QueryCurrentStockResVO>> result = chanjetSpi.invokeRetList(QUERY_CURRENT_STOCK,
new QueryCurrentStockReqVO(new QueryCurrentStockReqVO.QueryCurrentStockParamVO(doList.stream().map(StorageMatDO::getProjectSubCode).collect(Collectors.toList()))),
QueryCurrentStockResVO.class);
if(!result.isSuccess()){
throw exception(CALL_API_ERROR);
}
List<QueryCurrentStockResVO> dataList = result.getData();
if(dataList == null) dataList = new ArrayList<>(16);
for (StorageMatDO aDo : doList) {
List<QueryCurrentStockResVO> stockResVOList = dataList.stream().filter(vo -> aDo.getProjectSubCode().equals(vo.getInventoryCode())).collect(Collectors.toList());
if(CollUtil.isEmpty(stockResVOList)){
aDo.setStockQuantity(new BigDecimal(0));
}else{
QueryCurrentStockResVO resVO = stockResVOList.get(0);
BigDecimal stockQuantity = new BigDecimal(resVO.getAvailableQuantity());;
if(warehouseId != null && resVO.getWarehouseID().longValue() != warehouseId.longValue()){
stockQuantity = new BigDecimal(0);
}
aDo.setStockQuantity(stockQuantity);
}
}
}
/**
* idbom
* @param bomId
* @return
* @throws ChanjetApiException
*/
private List<BOMChildDTOs> queryProcessBomById(String bomId) throws ChanjetApiException {
// 设置为“否”,关闭所有与用友通信的接口
if(!getSystemParameters()) return null;
List<BOMChildDTOs> resultData = null;
QueryBomReqVO.QueryBomDTO queryBomDTO = new QueryBomReqVO.QueryBomDTO();
queryBomDTO.setID(bomId);
CommonResult<List<QueryBomResVO>> result = chanjetSpi.invokeRetList(QUERY_BOM, new QueryBomReqVO(queryBomDTO), QueryBomResVO.class);
if(!result.isSuccess()){
throw exception(CALL_API_ERROR);
}
if(CollUtil.isNotEmpty(result.getData())){
QueryBomResVO topLayer = result.getData().get(0);
resultData = topLayer.getBOMChildDTOs();
if(CollUtil.isNotEmpty(resultData)){
for (BOMChildDTOs dto : resultData) {
ChildBOM childBOM = dto.getChildBOM();
if(childBOM != null){
dto.setBOMChildDTOs(queryProcessBomById(childBOM.getID()));
}
}
}
}
return resultData;
}
/**
*
@ -553,6 +457,57 @@ public class ChanjetSchedule {
}
/**
*
* @throws ChanjetApiException
*/
@Transactional(rollbackFor = Exception.class)
public void createStorageOut() throws ChanjetApiException{
List<TplusStorageOutDO> tplusStorageOutDOS = tplusStorageOutMapper.selectList(TplusStorageOutDO::getIsSend,0);
Map<Long, List<TplusStorageOutDO>> existsDOGroupByStockID =
tplusStorageOutDOS.stream().collect(Collectors.groupingBy(TplusStorageOutDO::getStockId));
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
existsDOGroupByStockID.keySet().forEach(key->{
List<TplusStorageOutDO> vo= existsDOGroupByStockID.get(key);
StorageDO storage = storageMapper.selectById(key);
WarehouseDO warehouseDO =warehouseMapper.selectById(storage.getWhId());
CreateStockOutDTO dto = new CreateStockOutDTO();
ArrayList<RDRecordDetail> detailList = new ArrayList<>();
dto.setExternalCode(storage.getStockNo())
.setVoucherDate(sdf.format(new Date()))
.setRDRecordDetails(detailList)
.setWarehouse(new Warehouse(warehouseDO.getWhNo()))
.setDepartment(new DepartmentDTO().setCode(null).setName(null))
;
vo.forEach(mat -> {
RDRecordDetail detail = new RDRecordDetail();
detail.setCode(String.valueOf(mat.getId())).setBaseQuantity(mat.getStorageOkQty())
.setInventory(new Inventory(mat.getProjectSubCode()));
detailList.add(detail);
});
// 设置为“否”,关闭所有与用友通信的接口;为“是”,打开所有与用友通信的接口
if(getSystemParameters()) {
CommonResult<ResultResVO> result = null;
try {
result = chanjetSpi.invoke(CREATE_STOCK_OUT_ORDER, new CreateStockOutOrderReqVO(dto), ResultResVO.class);
} catch (ChanjetApiException e) {
throw new RuntimeException(e);
}
if (!result.isSuccess()) {
throw exception(CALL_API_ERROR);
}
}
});
}
@Transactional(rollbackFor = Exception.class)
public void createProjectOrderForJiShu() throws ChanjetApiException{

@ -7,12 +7,22 @@ import com.chanko.yunxi.mes.framework.operatelog.core.enums.OperateTypeEnum;
import com.chanko.yunxi.mes.module.biz.controller.admin.storage.vo.StoragePageReqVO;
import com.chanko.yunxi.mes.module.biz.controller.admin.storage.vo.StorageSaveReqVO;
import com.chanko.yunxi.mes.module.biz.controller.admin.storagemat.vo.StorageMatPageReqVO;
import com.chanko.yunxi.mes.module.biz.dal.dataobject.projectorder.ProjectOrderDO;
import com.chanko.yunxi.mes.module.biz.dal.dataobject.projectorder.ProjectOrderSubDO;
import com.chanko.yunxi.mes.module.biz.dal.dataobject.serialnumber.SerialNumberDO;
import com.chanko.yunxi.mes.module.biz.dal.dataobject.storage.StorageDO;
import com.chanko.yunxi.mes.module.biz.dal.dataobject.storagemat.StorageMatDO;
import com.chanko.yunxi.mes.module.biz.dal.dataobject.systemparameters.SystemParametersDO;
import com.chanko.yunxi.mes.module.biz.dal.dataobject.tpluslastestbom.TplusLastestBomDO;
import com.chanko.yunxi.mes.module.biz.dal.dataobject.tpluslasteststock.TplusLastestStockDO;
import com.chanko.yunxi.mes.module.biz.dal.dataobject.tplusstorageout.TplusStorageOutDO;
import com.chanko.yunxi.mes.module.biz.dal.mysql.projectorder.ProjectOrderMapper;
import com.chanko.yunxi.mes.module.biz.dal.mysql.projectorder.ProjectOrderSubMapper;
import com.chanko.yunxi.mes.module.biz.dal.mysql.storage.StorageMapper;
import com.chanko.yunxi.mes.module.biz.dal.mysql.systemparameters.SystemParametersMapper;
import com.chanko.yunxi.mes.module.biz.dal.mysql.tpluslastestbom.TplusLastestBomMapper;
import com.chanko.yunxi.mes.module.biz.dal.mysql.tpluslasteststock.TplusLastestStockMapper;
import com.chanko.yunxi.mes.module.biz.dal.mysql.tplusstorageout.TplusStorageOutMapper;
import com.chanko.yunxi.mes.module.biz.enums.CodeEnum;
import com.chanko.yunxi.mes.module.biz.enums.StockTypeEnum;
import com.chanko.yunxi.mes.module.biz.enums.SystemParmetersEnum;
@ -21,11 +31,13 @@ import com.chanko.yunxi.mes.module.biz.service.serialnumber.SerialNumberService;
import com.chanko.yunxi.mes.module.biz.service.storagemat.StorageMatService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@ -58,6 +70,22 @@ public class StorageServiceImpl implements StorageService {
@Resource
private SystemParametersMapper systemParametersMapper;
@Resource
private TplusLastestBomMapper tplusLastestBomMapper;
@Resource
private ProjectOrderMapper projectOrderMapper;
@Resource
private ProjectOrderSubMapper projectOrderSubMapper;
@Resource
private TplusStorageOutMapper tplusStorageOutMapper;
@Resource
private TplusLastestStockMapper tplusLastestStockMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public Long createStorage(StorageSaveReqVO createReqVO) {
@ -128,10 +156,91 @@ public class StorageServiceImpl implements StorageService {
}
}
if(OperateTypeEnum.AUDIT.name().equals(updateReqVO.getActive())){
List<TplusStorageOutDO> insertList = new ArrayList<>();
List<TplusStorageOutDO> updateList = new ArrayList<>();
if(OperateTypeEnum.AUDIT.name().equals(updateReqVO.getActive()) && !StringUtils.isEmpty(updateObj.getProjectSubCode())){
ProjectOrderDO projectOrderDO = projectOrderMapper.selectOne(ProjectOrderDO::getCode,updateObj.getProjectOrderCode());
List<ProjectOrderSubDO> projectOrderSubDOList = projectOrderSubMapper.selectListByProjectOrderId(projectOrderDO.getId());
List<String> codes =new ArrayList<>();
projectOrderSubDOList.forEach(po->{
codes.add(po.getProjectSubCode());
});
List<TplusLastestBomDO> tplusLastestBomDOS = tplusLastestBomMapper.selectListByStockId(codes,updateObj.getId());
tplusLastestBomDOS.forEach(to->{
TplusStorageOutDO tplusStorageOutDO =
tplusStorageOutMapper.selectOne(TplusStorageOutDO::getStockId,updateObj.getId(),
TplusStorageOutDO::getProductCode,to.getTopCode(),
TplusStorageOutDO::getProjectSubCode,to.getProjectSubCode());
if(tplusStorageOutDO==null){
tplusStorageOutDO = new TplusStorageOutDO();
tplusStorageOutDO.setId(null)
.setStockId(updateObj.getId())
.setStorageOkQty(to.getStorageOkQty())
.setProductCode(to.getTopCode())
.setProjectSubCode(to.getProjectSubCode())
.setProcedureId(to.getProcedureId())
.setIsSend(0);
insertList.add(tplusStorageOutDO);
}else{
tplusStorageOutDO.setStockId(updateObj.getId())
.setStorageOkQty(to.getStorageOkQty())
.setProductCode(to.getTopCode())
.setProjectSubCode(to.getProjectSubCode())
.setProcedureId(to.getProcedureId())
.setIsSend(0);
updateList.add(tplusStorageOutDO);
}
});
}
else if(OperateTypeEnum.AUDIT.name().equals(updateReqVO.getActive()) && updateObj.getMaterialMode().equals(2)) {
storageMatList.forEach(to->{
TplusStorageOutDO tplusStorageOutDO =
tplusStorageOutMapper.selectOne(TplusStorageOutDO::getStockId,updateObj.getId(),
TplusStorageOutDO::getProjectSubCode,to.getProjectSubCode());
if(tplusStorageOutDO==null){
tplusStorageOutDO = new TplusStorageOutDO();
tplusStorageOutDO.setId(null)
.setStockId(updateObj.getId())
.setStorageOkQty(to.getStorageOkQty())
.setProjectSubCode(to.getProjectSubCode())
.setProcedureId(to.getProcedureId())
.setIsSend(0);
insertList.add(tplusStorageOutDO);
}else{
tplusStorageOutDO.setStockId(updateObj.getId())
.setStorageOkQty(to.getStorageOkQty())
.setProjectSubCode(to.getProjectSubCode())
.setProcedureId(to.getProcedureId())
.setIsSend(0);
updateList.add(tplusStorageOutDO);
}
});
}
if(CollUtil.isNotEmpty(insertList)) {
tplusStorageOutMapper.insertBatch(insertList);
insertList.forEach(ino->{
TplusLastestStockDO tplusLastestStockDO =
tplusLastestStockMapper.selectOne(TplusLastestStockDO::getInventoryCode,ino.getProductCode(),
TplusLastestStockDO::getWarehouseId,updateObj.getWhId());
if(tplusLastestStockDO!=null){
tplusLastestStockDO.setAvailableQuantity(new BigDecimal(tplusLastestStockDO.getAvailableQuantity()).subtract(ino.getStorageOkQty()).toString());
tplusLastestStockMapper.updateById(tplusLastestStockDO);
}
});
}
if(CollUtil.isNotEmpty(updateList)) tplusStorageOutMapper.updateBatch(updateList);
// // 如为提交同步生成出库单
// if(updateObj.getStockType() == StockTypeEnum.OUT.getCode()){

@ -0,0 +1,55 @@
package com.chanko.yunxi.mes.module.biz.service.tplusstorageout;
import java.util.*;
import javax.validation.*;
import com.chanko.yunxi.mes.module.biz.controller.admin.tplusstorageout.vo.*;
import com.chanko.yunxi.mes.module.biz.dal.dataobject.tplusstorageout.TplusStorageOutDO;
import com.chanko.yunxi.mes.framework.common.pojo.PageResult;
import com.chanko.yunxi.mes.framework.common.pojo.PageParam;
/**
* Service
*
* @author
*/
public interface TplusStorageOutService {
/**
*
*
* @param createReqVO
* @return
*/
Long createTplusStorageOut(@Valid TplusStorageOutSaveReqVO createReqVO);
/**
*
*
* @param updateReqVO
*/
void updateTplusStorageOut(@Valid TplusStorageOutSaveReqVO updateReqVO);
/**
*
*
* @param id
*/
void deleteTplusStorageOut(Long id);
/**
*
*
* @param id
* @return
*/
TplusStorageOutDO getTplusStorageOut(Long id);
/**
*
*
* @param pageReqVO
* @return
*/
PageResult<TplusStorageOutDO> getTplusStorageOutPage(TplusStorageOutPageReqVO pageReqVO);
}

@ -0,0 +1,74 @@
package com.chanko.yunxi.mes.module.biz.service.tplusstorageout;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import com.chanko.yunxi.mes.module.biz.controller.admin.tplusstorageout.vo.*;
import com.chanko.yunxi.mes.module.biz.dal.dataobject.tplusstorageout.TplusStorageOutDO;
import com.chanko.yunxi.mes.framework.common.pojo.PageResult;
import com.chanko.yunxi.mes.framework.common.pojo.PageParam;
import com.chanko.yunxi.mes.framework.common.util.object.BeanUtils;
import com.chanko.yunxi.mes.module.biz.dal.mysql.tplusstorageout.TplusStorageOutMapper;
import static com.chanko.yunxi.mes.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.chanko.yunxi.mes.module.biz.enums.ErrorCodeConstants.*;
/**
* Service
*
* @author
*/
@Service
@Validated
public class TplusStorageOutServiceImpl implements TplusStorageOutService {
@Resource
private TplusStorageOutMapper tplusStorageOutMapper;
@Override
public Long createTplusStorageOut(TplusStorageOutSaveReqVO createReqVO) {
// 插入
TplusStorageOutDO tplusStorageOut = BeanUtils.toBean(createReqVO, TplusStorageOutDO.class);
tplusStorageOutMapper.insert(tplusStorageOut);
// 返回
return tplusStorageOut.getId();
}
@Override
public void updateTplusStorageOut(TplusStorageOutSaveReqVO updateReqVO) {
// 校验存在
validateTplusStorageOutExists(updateReqVO.getId());
// 更新
TplusStorageOutDO updateObj = BeanUtils.toBean(updateReqVO, TplusStorageOutDO.class);
tplusStorageOutMapper.updateById(updateObj);
}
@Override
public void deleteTplusStorageOut(Long id) {
// 校验存在
validateTplusStorageOutExists(id);
// 删除
tplusStorageOutMapper.deleteById(id);
}
private void validateTplusStorageOutExists(Long id) {
if (tplusStorageOutMapper.selectById(id) == null) {
throw exception(TPLUS_STORAGE_OUT_NOT_EXISTS);
}
}
@Override
public TplusStorageOutDO getTplusStorageOut(Long id) {
return tplusStorageOutMapper.selectById(id);
}
@Override
public PageResult<TplusStorageOutDO> getTplusStorageOutPage(TplusStorageOutPageReqVO pageReqVO) {
return tplusStorageOutMapper.selectPage(pageReqVO);
}
}

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.chanko.yunxi.mes.module.biz.dal.mysql.tplusstorageout.TplusStorageOutMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>

@ -474,4 +474,23 @@ alter table wms_storage add column `material_mode` int(2) default null comment '
alter table project_sale_order add `package_status` int(2) default 2 comment '包装状态';
alter table wms_storage_mat add column `pre_amount` decimal(10,2) DEFAULT NULL COMMENT '预估消耗值';
alter table wms_storage_mat add column `stock_quantity` decimal(10,2) DEFAULT NULL COMMENT '库存';
alter table wms_storage_mat add column `stock_quantity` decimal(10,2) DEFAULT NULL COMMENT '库存';
drop table if exists `tplus_storage_out`;
CREATE TABLE `tplus_storage_out` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增字段,唯一',
`stock_id` bigint(20) DEFAULT NULL COMMENT '出库id',
`storage_ok_qty` decimal(10,2) DEFAULT NULL COMMENT '领料数量',
`product_code` varchar(255) DEFAULT NULL COMMENT '产品编码',
`project_sub_code` varchar(255) DEFAULT NULL COMMENT '物料编码',
`procedure_id` bigint(20) DEFAULT NULL COMMENT '工序id',
`creator` varchar(64) DEFAULT '' COMMENT '创建者',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`updater` varchar(64) DEFAULT '' COMMENT '更新者',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
`tenant_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '租户编号',
`is_send` int(2) DEFAULT NULL COMMENT '是否推送',
PRIMARY KEY (`id`)
) ENGINE=InnoDB COMMENT='用友生产领料表';
Loading…
Cancel
Save