| | |
| | | package com.doumee.service.business.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.doumee.core.constants.ResponseStatus; |
| | | import com.doumee.core.exception.BusinessException; |
| | | import com.doumee.core.model.LoginUserInfo; |
| | |
| | | import com.doumee.dao.business.YwStocktakingRecordMapper; |
| | | import com.doumee.dao.business.YwWarehouseMapper; |
| | | import com.doumee.dao.business.model.*; |
| | | import com.doumee.dao.system.SystemUserMapper; |
| | | import com.doumee.dao.system.join.NoticesJoinMapper; |
| | | import com.doumee.dao.system.model.Notices; |
| | | import com.doumee.dao.system.model.SystemUser; |
| | | import com.doumee.service.business.YwStocktakingService; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | private NoticesJoinMapper noticesJoinMapper; |
| | | |
| | | @Autowired |
| | | private SystemUserMapper systemUserMapper; |
| | | |
| | | @Autowired |
| | | private RedisTemplate<String, Object> redisTemplate; |
| | | |
| | | @Override |
| | |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到仓库数据"); |
| | | } |
| | | //判断当前仓库当前日期是否存在盘点单 |
| | | if(ywStocktakingMapper.selectCount(new QueryWrapper<YwStocktaking>().lambda().eq(YwStocktaking::getIsdeleted,Constants.ZERO).eq(YwStocktaking::getStatus,Constants.ZERO) |
| | | .eq(YwStocktaking::getWarehouseId,ywStocktaking.getWarehouseId()).apply(" DATE(PLAN_DATE) = '" + DateUtil.formatDate(ywStocktaking.getPlanDate(),"yyyy-MM-dd") +"'" ))>0){ |
| | | if(ywStocktakingMapper.selectCount(new QueryWrapper<YwStocktaking>().lambda() |
| | | .eq(YwStocktaking::getIsdeleted,Constants.ZERO) |
| | | .in(YwStocktaking::getStatus,Constants.ZERO,Constants.ONE) |
| | | .eq(YwStocktaking::getWarehouseId,ywStocktaking.getWarehouseId()) |
| | | .apply(" DATE(PLAN_DATE) = '" + DateUtil.formatDate(ywStocktaking.getPlanDate(),"yyyy-MM-dd") +"'" ))>0){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"["+DateUtil.formatDate(ywStocktaking.getPlanDate(),"yyyy-MM-dd")+"]["+ywWarehouse.getName()+"]已有盘点单,不可重复发起盘点"); |
| | | } |
| | | SystemUser systemUser = systemUserMapper.selectById(ywStocktaking.getUserId()); |
| | | if(Objects.isNull(systemUser)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到盘点人信息"); |
| | | } |
| | | LoginUserInfo loginUserInfo = ywStocktaking.getLoginUserInfo(); |
| | | ywStocktaking.setCreator(loginUserInfo.getId()); |
| | |
| | | notices.setType(notices.getObjType()); |
| | | notices.setUserId(ywStocktaking.getUserId()); |
| | | notices.setStatus(Constants.ZERO); |
| | | //整理json数据 |
| | | Map<String,Object> jsonMap = new HashMap<>(); |
| | | jsonMap.put("key1","盘点单"+ywStocktaking.getCode()); |
| | | jsonMap.put("key2", DateUtil.getFomartDate(ywStocktaking.getPlanDate(),"yyyy-MM-dd")); |
| | | jsonMap.put("key3", ywWarehouse.getName()); |
| | | jsonMap.put("key4", systemUser.getRealname()); |
| | | notices.setParam2(JSONObject.toJSONString(jsonMap)); |
| | | notices.setParam3(Constants.ZERO+""); |
| | | noticesJoinMapper.insert(notices); |
| | | return ywStocktaking.getId(); |
| | | } |
| | |
| | | .eq(YwStocktaking::getId,id) |
| | | ); |
| | | //标记待办删除 |
| | | noticesJoinMapper.update(null,new UpdateWrapper<Notices>().lambda().set(Notices::getIsdeleted,Constants.ONE) |
| | | noticesJoinMapper.update(null,new UpdateWrapper<Notices>().lambda() |
| | | .set(Notices::getIsdeleted,Constants.ONE) |
| | | .eq(Notices::getIsdeleted,Constants.ZERO) |
| | | .eq(Notices::getObjType,Constants.ZERO) |
| | | .eq(Notices::getObjId,id) |
| | |
| | | .set(YwStocktaking::getEditor,loginUserInfo.getId()) |
| | | .set(YwStocktaking::getStatus,Constants.THREE).eq(YwStocktaking::getId,id)); |
| | | //标记待办删除 |
| | | noticesJoinMapper.update(null,new UpdateWrapper<Notices>().lambda().set(Notices::getIsdeleted,Constants.ONE) |
| | | noticesJoinMapper.update(null,new UpdateWrapper<Notices>().lambda() |
| | | .set(Notices::getIsdeleted,Constants.ONE) |
| | | .eq(Notices::getIsdeleted,Constants.ZERO) |
| | | .eq(Notices::getObjType,Constants.ZERO) |
| | | .eq(Notices::getObjId,id) |
| | |
| | | if(Objects.isNull(model)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到盘点单数据"); |
| | | } |
| | | if(model.getPlanDate().getTime()<System.currentTimeMillis()){ |
| | | if(model.getPlanDate().getTime()>System.currentTimeMillis()){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"未到开始时间,无法进行该操作"); |
| | | } |
| | | if(Constants.equalsInteger(model.getStatus(),Constants.ZERO)&&Constants.equalsInteger(model.getIsdeleted(),Constants.ZERO)){ |
| | |
| | | |
| | | //标记待办已处理 |
| | | noticesJoinMapper.update(null,new UpdateWrapper<Notices>().lambda() |
| | | .set(Notices::getStatus,Constants.ONE) |
| | | .set(Notices::getParam3,Constants.ONE) |
| | | .eq(Notices::getStatus,Constants.ZERO) |
| | | .eq(Notices::getIsdeleted,Constants.ZERO) |
| | | .eq(Notices::getObjType,Constants.ZERO) |
| | | .eq(Notices::getObjId,id) |
| | |
| | | ywStocktakingRecord.setIsdeleted(Constants.ZERO); |
| | | ywStocktakingRecord.setStatus(Constants.ZERO); |
| | | ywStocktakingRecord.setMaterialId(ywStock.getMaterialId()); |
| | | ywStocktakingRecord.setUserId(model.getUserId()+""); |
| | | ywStocktakingRecord.setStock(ywStock.getStock()); |
| | | ywStocktakingRecord.setStocktakingId(model.getId()); |
| | | ywStocktakingRecordList.add(ywStocktakingRecord); |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class,BusinessException.class}) |
| | | public void finishById(Integer id, LoginUserInfo loginUserInfo) { |
| | | public void finishById(Integer id, YwOutinboundServiceImpl ywOutinboundService, LoginUserInfo loginUserInfo) { |
| | | YwStocktaking model = ywStocktakingMapper.selectById(id); |
| | | if(Objects.isNull(model)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到盘点单数据"); |
| | |
| | | } |
| | | List<YwStocktakingRecord> recordList = ywStocktakingRecordMapper.selectList(new QueryWrapper<YwStocktakingRecord>().lambda() |
| | | .eq(YwStocktakingRecord::getStocktakingId,id).eq(YwStocktakingRecord::getIsdeleted,Constants.ZERO)); |
| | | //盘盈数据列表 |
| | | List<YwOutinboundRecord> inBoundRecordList = new ArrayList<>(); |
| | | //盘亏数据列表 |
| | | List<YwOutinboundRecord> outBoundRecordList = new ArrayList<>(); |
| | | for (YwStocktakingRecord ywStocktakingRecord:recordList) { |
| | | //提交时 未进行盘点的明细数据 |
| | | if(Constants.equalsInteger(ywStocktakingRecord.getStatus(),Constants.ZERO)){ |
| | |
| | | .set(YwStocktakingRecord::getUserId,loginUserInfo.getId()) |
| | | .eq(YwStocktakingRecord::getId,ywStocktakingRecord.getId()) |
| | | ); |
| | | continue; |
| | | } |
| | | //查询库存信息 进行库存更新 |
| | | YwStock ywStock = ywStockMapper.selectOne(new QueryWrapper<YwStock>().lambda().eq(YwStock::getMaterialId,ywStocktakingRecord.getMaterialId()) |
| | | .eq(YwStock::getWarehouseId,model.getWarehouseId()).eq(YwStock::getStock,ywStocktakingRecord.getStock())); |
| | | if(Objects.isNull(ywStock)){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"库存信息异常,请联系管理员"); |
| | | if(ywStock.getStock().compareTo(ywStocktakingRecord.getActStock())<Constants.ZERO ){ |
| | | YwOutinboundRecord ywOutinboundRecord = new YwOutinboundRecord(); |
| | | ywOutinboundRecord.setMaterialId(ywStock.getMaterialId()); |
| | | ywOutinboundRecord.setStock(ywStocktakingRecord.getActStock().subtract(ywStock.getStock())); |
| | | inBoundRecordList.add(ywOutinboundRecord); |
| | | }else if(ywStock.getStock().compareTo(ywStocktakingRecord.getActStock())>Constants.ZERO ){ |
| | | YwOutinboundRecord ywOutinboundRecord = new YwOutinboundRecord(); |
| | | ywOutinboundRecord.setMaterialId(ywStock.getMaterialId()); |
| | | ywOutinboundRecord.setStock(ywStock.getStock().subtract(ywStocktakingRecord.getActStock())); |
| | | outBoundRecordList.add(ywOutinboundRecord); |
| | | } |
| | | if(ywStocktakingRecord.getActStock().compareTo(BigDecimal.ZERO)==Constants.ZERO){ |
| | | ywStockMapper.deleteById(ywStock.getId()); |
| | | }else { |
| | | ywStockMapper.update(new UpdateWrapper<YwStock>().lambda().set(YwStock::getStock,ywStocktakingRecord.getActStock()).eq(YwStock::getId,ywStock.getId())); |
| | | } |
| | | // if(Objects.isNull(ywStock)){ |
| | | // throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"库存信息异常,请联系管理员"); |
| | | // } |
| | | // if(ywStocktakingRecord.getActStock().compareTo(BigDecimal.ZERO)==Constants.ZERO){ |
| | | // ywStockMapper.deleteById(ywStock.getId()); |
| | | // }else { |
| | | // ywStockMapper.update(new UpdateWrapper<YwStock>().lambda().set(YwStock::getStock,ywStocktakingRecord.getActStock()).eq(YwStock::getId,ywStock.getId())); |
| | | // } |
| | | } |
| | | ywStocktakingMapper.update(new UpdateWrapper<YwStocktaking>().lambda() |
| | | .set(YwStocktaking::getEditDate,DateUtil.getCurrDateTime()) |
| | |
| | | .set(YwStocktaking::getEditor,loginUserInfo.getId()) |
| | | .set(YwStocktaking::getStatus,Constants.TWO) |
| | | .eq(YwStocktaking::getId,model.getId())); |
| | | //生产盘盈的入库单 |
| | | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(inBoundRecordList)){ |
| | | YwOutinbound ywOutinbound = new YwOutinbound(); |
| | | ywOutinbound.setDoneDate(new Date()); |
| | | ywOutinbound.setWarehouseId(model.getWarehouseId()); |
| | | ywOutinbound.setType(4); |
| | | ywOutinbound.setOrigin(1); |
| | | ywOutinbound.setContent("盘点单【"+model.getCode() +"】处理生成盘盈数据"); |
| | | ywOutinbound.setStatus(Constants.ZERO); |
| | | ywOutinbound.setRecordList(inBoundRecordList); |
| | | ywOutinbound.setLoginUserInfo(loginUserInfo); |
| | | ywOutinboundService.create(ywOutinbound); |
| | | } |
| | | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(outBoundRecordList)){ |
| | | YwOutinbound ywOutinbound = new YwOutinbound(); |
| | | ywOutinbound.setDoneDate(new Date()); |
| | | ywOutinbound.setWarehouseId(model.getWarehouseId()); |
| | | ywOutinbound.setType(10); |
| | | ywOutinbound.setOrigin(1); |
| | | ywOutinbound.setContent("盘点单【"+model.getCode() +"】处理生成盘亏数据"); |
| | | ywOutinbound.setStatus(Constants.ZERO); |
| | | ywOutinbound.setRecordList(outBoundRecordList); |
| | | ywOutinbound.setLoginUserInfo(loginUserInfo); |
| | | ywOutinboundService.create(ywOutinbound); |
| | | } |
| | | |
| | | //标记待办已完成 |
| | | noticesJoinMapper.update(null,new UpdateWrapper<Notices>().lambda() |
| | | .set(Notices::getStatus,Constants.ONE) |
| | | .set(Notices::getParam3,Constants.TWO) |
| | | .eq(Notices::getIsdeleted,Constants.ZERO) |
| | | .eq(Notices::getObjType,Constants.ZERO) |
| | | .eq(Notices::getObjId,id) |
| | | ); |
| | | |
| | | } |
| | | |
| | |
| | | if(Objects.isNull(model)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到盘点单数据"); |
| | | } |
| | | |
| | | SystemUser systemUser = systemUserMapper.selectById(ywStocktaking.getUserId()); |
| | | if(Objects.isNull(systemUser)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到盘点人信息"); |
| | | } |
| | | |
| | | YwWarehouse ywWarehouse = ywWarehouseMapper.selectById(ywStocktaking.getWarehouseId()); |
| | | if(Objects.isNull(ywWarehouse)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到仓库数据"); |
| | |
| | | //标记待办已处理 |
| | | noticesJoinMapper.update(null,new UpdateWrapper<Notices>().lambda() |
| | | .set(Notices::getStatus,Constants.ONE) |
| | | .eq(Notices::getIsdeleted,Constants.ZERO) |
| | | .eq(Notices::getIsdeleted,Constants.ONE) |
| | | .eq(Notices::getObjType,Constants.ZERO) |
| | | .eq(Notices::getObjId,ywStocktaking.getId()) |
| | | ); |
| | |
| | | notices.setType(notices.getObjType()); |
| | | notices.setUserId(ywStocktaking.getUserId()); |
| | | notices.setStatus(Constants.ZERO); |
| | | //整理json数据 |
| | | Map<String,Object> jsonMap = new HashMap<>(); |
| | | jsonMap.put("key1","盘点单"+ywStocktaking.getCode()); |
| | | jsonMap.put("key2", DateUtil.getFomartDate(ywStocktaking.getPlanDate(),"yyyy-MM-dd")); |
| | | jsonMap.put("key3", ywWarehouse.getName()); |
| | | jsonMap.put("key4", systemUser.getRealname()); |
| | | notices.setParam2(JSONObject.toJSONString(jsonMap)); |
| | | notices.setParam3(Constants.ZERO+""); |
| | | noticesJoinMapper.insert(notices); |
| | | |
| | | |
| | |
| | | public YwStocktaking getDetail(Integer id) { |
| | | MPJLambdaWrapper<YwStocktaking> queryWrapper = new MPJLambdaWrapper<>(); |
| | | queryWrapper.selectAll(YwStocktaking.class) |
| | | .select(" s.name ", YwStocktaking::getUserName) |
| | | .select(" s1.name ",YwStocktaking::getCreateName) |
| | | .select(" s.realname ", YwStocktaking::getUserName) |
| | | .select(" s1.realname ",YwStocktaking::getCreateName) |
| | | .selectAs(YwWarehouse::getName,YwStocktaking::getWarehouseName) |
| | | .leftJoin(YwWarehouse.class,YwWarehouse::getId,YwStocktaking::getWarehouseId) |
| | | .leftJoin("system_user s on t.user_id = s.id") |
| | |
| | | Utils.MP.blankToNull(pageWrap.getModel()); |
| | | YwStocktaking model = pageWrap.getModel(); |
| | | queryWrapper.selectAll(YwStocktaking.class) |
| | | .select(" s.name ", YwStocktaking::getUserName) |
| | | .select(" s1.name ",YwStocktaking::getCreateName) |
| | | .select(" s.realname ", YwStocktaking::getUserName) |
| | | .select(" s1.realname ",YwStocktaking::getCreateName) |
| | | .selectAs(YwWarehouse::getName,YwStocktaking::getWarehouseName) |
| | | .leftJoin(YwWarehouse.class,YwWarehouse::getId,YwStocktaking::getWarehouseId) |
| | | .leftJoin("system_user s on t.user_id = s.id") |
| | |
| | | .eq(YwStocktaking::getIsdeleted,Constants.ZERO) |
| | | .like(StringUtils.isNotBlank(model.getName()),YwStocktaking::getName,model.getName()) |
| | | .eq(Objects.nonNull(model.getStatus()),YwStocktaking::getStatus,model.getStatus()) |
| | | .eq(Objects.nonNull(model.getUserId()),YwStocktaking::getUserId,model.getUserId()) |
| | | .orderByAsc(YwStocktaking::getStatus) |
| | | .orderByDesc(YwStocktaking::getPlanDate) |
| | | ; |
| | | |
| | | IPage iPage = ywStocktakingMapper.selectJoinPage(page, YwStocktaking.class,queryWrapper); |
| | | return PageData.from(iPage); |
| | | } |