| | |
| | | package com.fzzy.igds.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.fzzy.igds.constant.AuditStatus; |
| | | import com.fzzy.igds.constant.Constant; |
| | | import com.fzzy.igds.data.ExportWordParam; |
| | | import com.fzzy.igds.data.NoticeDto; |
| | | import com.fzzy.igds.data.NoticeParam; |
| | | import com.fzzy.igds.mapper.InoutNoticeMapper; |
| | | import com.fzzy.igds.repository.InoutNoticeInRepository; |
| | | import com.fzzy.igds.repository.InoutNoticeOutRepository; |
| | | import com.fzzy.igds.domain.InoutNoticeIn; |
| | | import com.fzzy.igds.domain.InoutNoticeOut; |
| | | import com.fzzy.igds.domain.*; |
| | | import com.fzzy.igds.mapper.InoutNoticeInMapper; |
| | | import com.fzzy.igds.mapper.InoutNoticeOutMapper; |
| | | import com.fzzy.igds.utils.ContextUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.time.DateFormatUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.data.domain.Page; |
| | | import org.springframework.data.domain.Pageable; |
| | | import org.springframework.data.jpa.domain.Specification; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import javax.annotation.Resource; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @Description 出入库通知单service层,包含入库通知单和出库通知单 |
| | |
| | | public class InoutNoticeService { |
| | | |
| | | @Resource |
| | | private InoutNoticeInRepository noticeInRepository; |
| | | private InoutNoticeInMapper noticeInMapper; |
| | | @Resource |
| | | private InoutNoticeOutRepository noticeOutRepository; |
| | | private InoutNoticeOutMapper noticeOutMapper; |
| | | @Resource |
| | | private InoutNoticeMapper noticeMapper; |
| | | private DepotService depotService; |
| | | @Resource |
| | | private CoreDeptService coreDeptService; |
| | | @Resource |
| | | private PledgeContractService pledgeContractService; |
| | | |
| | | /*----------------------入库通知单信息-------------------------*/ |
| | | /** |
| | | * JPA分页查询数据 |
| | | * |
| | | * @param specification |
| | | * @param pageable |
| | | * @return |
| | | * 分页查询数据 |
| | | * @param page |
| | | * @param param |
| | | */ |
| | | public Page<InoutNoticeIn> queryAllNoticeIn(Specification<InoutNoticeIn> specification, Pageable pageable) { |
| | | return noticeInRepository.findAll(specification, pageable); |
| | | public void pageQueryIn(Page<InoutNoticeIn> page, NoticeParam param) { |
| | | QueryWrapper<InoutNoticeIn> queryWrapper = new QueryWrapper<>(); |
| | | |
| | | if(null == param) { |
| | | param = new NoticeParam(); |
| | | } |
| | | param.setCompanyId(ContextUtil.getCompanyId()); |
| | | |
| | | queryWrapper.eq("company_id", param.getCompanyId()); |
| | | if(StringUtils.isNotBlank(param.getCustomerName())){ |
| | | queryWrapper.like("customer_name", param.getCustomerName()); |
| | | } |
| | | if(StringUtils.isNotBlank(param.getFoodVariety())){ |
| | | queryWrapper.like("food_variety", param.getFoodVariety()); |
| | | } |
| | | if(StringUtils.isNotBlank(param.getCompleteStatus())){ |
| | | queryWrapper.like("complete_status", param.getCompleteStatus()); |
| | | } |
| | | |
| | | noticeInMapper.selectPage(page, queryWrapper); |
| | | } |
| | | |
| | | /** |
| | | * JPA查询数据 |
| | | * @param companyId |
| | | * @param deptId |
| | | * 根据条件查询 |
| | | * @return |
| | | */ |
| | | public List<InoutNoticeIn> listNoticeIn(String companyId, String deptId) { |
| | | return noticeInRepository.listNoticeIn(companyId, deptId, Constant.COMPLETE_STATUS_NONE); |
| | | public List<InoutNoticeIn> getNoticeIn(NoticeParam param) { |
| | | |
| | | QueryWrapper<InoutNoticeIn> queryWrapper = new QueryWrapper<>(); |
| | | if(StringUtils.isNotBlank(param.getCompanyId())){ |
| | | queryWrapper.eq("company_id", param.getCompanyId()); |
| | | } |
| | | if(StringUtils.isNotBlank(param.getDeptId())){ |
| | | queryWrapper.eq("dept_id", param.getDeptId()); |
| | | } |
| | | if(StringUtils.isNotBlank(param.getCompleteStatus())){ |
| | | queryWrapper.eq("complete_status", param.getCompleteStatus()); |
| | | } |
| | | if(StringUtils.isNotBlank(param.getKey())){ |
| | | queryWrapper.like("name", param.getKey()); |
| | | } |
| | | queryWrapper.orderByDesc("create_time"); |
| | | |
| | | return noticeInMapper.selectList(queryWrapper); |
| | | } |
| | | |
| | | /** |
| | | * jpa 获取信息 |
| | | * 根据条件查询 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | public InoutNoticeIn getNoticeInOne(String id) { |
| | | |
| | | QueryWrapper<InoutNoticeIn> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("id", id); |
| | | return noticeInMapper.selectOne(queryWrapper); |
| | | } |
| | | |
| | | /** |
| | | * 查询数据 |
| | | * @param companyId |
| | | * @return |
| | | */ |
| | |
| | | if (StringUtils.isEmpty(companyId)) { |
| | | companyId = ContextUtil.getCompanyId(); |
| | | } |
| | | return noticeInRepository.listNoticeIn(companyId, Constant.COMPLETE_STATUS_NONE); |
| | | NoticeParam param = new NoticeParam(); |
| | | param.setCompanyId(companyId); |
| | | param.setCompleteStatus(Constant.COMPLETE_STATUS_NONE); |
| | | return this.getNoticeIn(param); |
| | | } |
| | | |
| | | /** |
| | | * JPA - 保存更新数据 |
| | | * - 保存更新数据 |
| | | * |
| | | * @param data |
| | | * @return |
| | | */ |
| | | public String saveOrUpdateIn(InoutNoticeIn data) { |
| | | if (Constant.YN_Y.equals(data.getTag())) { |
| | | //如果入库通知单类型为库区通知单,验证仓库是否是未解压得仓库,是则不允许保存 |
| | | //获取所有质押合同数据 |
| | | List<PledgeContract> pledgeContracts = pledgeContractService.listAll(null); |
| | | if("10".equals(data.getType())){ |
| | | //在质押合同找到未解压,且质押仓库包含当前仓库的数据 |
| | | for (PledgeContract pledgeContract : pledgeContracts) { |
| | | if(pledgeContract.getDepotIds().contains(data.getDepotId())){ |
| | | if(pledgeContract.getStatus().equals(Constant.YN_N)){ |
| | | return "入库仓库未解压,无法保存!"; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //如果入库通知单类型为监管通知单 |
| | | if("20".equals(data.getType())){ |
| | | //1.验证银行是否填写,未填写,则不允许保存 |
| | | if(StringUtils.isEmpty(data.getBankId())){ |
| | | return "监督银行不能为空!"; |
| | | |
| | | } |
| | | //2.验证银行和仓库的对应关系是否正确,不正确则不允许保存 |
| | | //在质押合同找到未解压,且质押仓库包含当前仓库的 银行-仓库(质押合同关系) |
| | | Map<String, PledgeContract> bankDepotMap = new HashMap<>(); |
| | | for (PledgeContract pledgeContract : pledgeContracts) { |
| | | if(pledgeContract.getDepotIds().contains(data.getDepotId())){ |
| | | if(pledgeContract.getStatus().equals(Constant.YN_N)){ |
| | | bankDepotMap.put(pledgeContract.getPledgeBank(), pledgeContract); |
| | | } |
| | | } |
| | | } |
| | | //在map中寻找匹配银行的数据,如果没有匹配的数据,则不允许保存 |
| | | if(!bankDepotMap.containsKey(data.getBankId())){ |
| | | return "未找到对应的质押合同,请检查监督银行或者入库仓库填写是否正确!"; |
| | | |
| | | } |
| | | } |
| | | |
| | | if (null == data.getUpdateBy()) { |
| | | data.setUpdateBy(ContextUtil.getLoginUserName()); |
| | | data.setUpdateTime(new Date()); |
| | | data.setCreateBy(ContextUtil.getLoginUserName()); |
| | | data.setCreateTime(new Date()); |
| | | data.setAuditStatus(Constant.COMPLETE_STATUS_NONE); |
| | | data.setAuditStatus(AuditStatus.STATUS_10.getCode()); |
| | | data.setCompleteStatus(Constant.COMPLETE_STATUS_NONE); |
| | | noticeInMapper.insert(data); |
| | | } else { |
| | | data.setUpdateBy(ContextUtil.getLoginUserName()); |
| | | data.setUpdateTime(new Date()); |
| | | noticeInMapper.updateById(data); |
| | | } |
| | | data.setUpdateBy(ContextUtil.getLoginUserName()); |
| | | data.setUpdateTime(new Date()); |
| | | noticeInRepository.save(data); |
| | | |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * JPA - 删除数据 |
| | | * - 删除数据 |
| | | * |
| | | * @param data |
| | | * @return |
| | | */ |
| | | public String delDataIn(InoutNoticeIn data) { |
| | | noticeInRepository.delete(data); |
| | | noticeInMapper.deleteById(data); |
| | | return null; |
| | | } |
| | | |
| | | /*----------------------出库通知单信息-------------------------*/ |
| | | /** |
| | | * JPA分页查询数据 |
| | | * |
| | | * @param specification |
| | | * @param pageable |
| | | * @return |
| | | * 分页查询数据 |
| | | * @param page |
| | | * @param param |
| | | */ |
| | | public Page<InoutNoticeOut> queryAllNoticeOut(Specification<InoutNoticeOut> specification, Pageable pageable) { |
| | | return noticeOutRepository.findAll(specification, pageable); |
| | | public void pageQueryOut(Page<InoutNoticeOut> page, NoticeParam param) { |
| | | QueryWrapper<InoutNoticeOut> queryWrapper = new QueryWrapper<>(); |
| | | |
| | | if(null == param) { |
| | | param = new NoticeParam(); |
| | | } |
| | | param.setCompanyId(ContextUtil.getCompanyId()); |
| | | |
| | | queryWrapper.eq("company_id", param.getCompanyId()); |
| | | if(StringUtils.isNotBlank(param.getCustomerName())){ |
| | | queryWrapper.like("customer_name", param.getCustomerName()); |
| | | } |
| | | if(StringUtils.isNotBlank(param.getFoodVariety())){ |
| | | queryWrapper.like("food_variety", param.getFoodVariety()); |
| | | } |
| | | if(StringUtils.isNotBlank(param.getCompleteStatus())){ |
| | | queryWrapper.like("complete_status", param.getCompleteStatus()); |
| | | } |
| | | |
| | | noticeOutMapper.selectPage(page, queryWrapper); |
| | | } |
| | | |
| | | /** |
| | | * JPA查询数据 |
| | | * @param companyId |
| | | * @param deptId |
| | | * 根据条件查询 |
| | | * @return |
| | | */ |
| | | public List<InoutNoticeOut> listNoticeOut(String companyId, String deptId) { |
| | | return noticeOutRepository.listNoticeOut(companyId, deptId, Constant.COMPLETE_STATUS_NONE); |
| | | public List<InoutNoticeOut> getNoticeOut(NoticeParam param) { |
| | | QueryWrapper<InoutNoticeOut> queryWrapper = new QueryWrapper<>(); |
| | | if(StringUtils.isNotBlank(param.getCompanyId())){ |
| | | queryWrapper.eq("company_id", param.getCompanyId()); |
| | | } |
| | | if(StringUtils.isNotBlank(param.getDeptId())){ |
| | | queryWrapper.eq("dept_id", param.getDeptId()); |
| | | } |
| | | if(StringUtils.isNotBlank(param.getCompleteStatus())){ |
| | | queryWrapper.eq("complete_status", param.getCompleteStatus()); |
| | | } |
| | | if(StringUtils.isNotBlank(param.getKey())){ |
| | | queryWrapper.like("name", param.getKey()); |
| | | } |
| | | queryWrapper.orderByDesc("create_time"); |
| | | |
| | | return noticeOutMapper.selectList(queryWrapper); |
| | | } |
| | | |
| | | /** |
| | | * 根据条件查询 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | public InoutNoticeOut getNoticeOutOne(String id) { |
| | | |
| | | QueryWrapper<InoutNoticeOut> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("id", id); |
| | | return noticeOutMapper.selectOne(queryWrapper); |
| | | } |
| | | |
| | | /** |
| | |
| | | if (StringUtils.isEmpty(companyId)) { |
| | | companyId = ContextUtil.getCompanyId(); |
| | | } |
| | | return noticeOutRepository.listNoticeOut(companyId, Constant.COMPLETE_STATUS_NONE); |
| | | NoticeParam param = new NoticeParam(); |
| | | param.setCompanyId(companyId); |
| | | param.setCompleteStatus(Constant.COMPLETE_STATUS_NONE); |
| | | return this.getNoticeOut(param); |
| | | } |
| | | |
| | | /** |
| | | * JPA - 保存更新数据 |
| | | * - 保存更新数据 |
| | | * |
| | | * @param data |
| | | * @return |
| | | */ |
| | | public String saveOrUpdateOut(InoutNoticeOut data) { |
| | | if (Constant.YN_Y.equals(data.getTag())) { |
| | | //如果出库通知单类型为库区通知单,验证仓库是否是未解压得仓库,是则不允许保存 |
| | | //获取所有质押合同数据 |
| | | List<PledgeContract> pledgeContracts = pledgeContractService.listAll(null); |
| | | if("10".equals(data.getType())){ |
| | | //在质押合同找到未解压,且质押仓库包含当前仓库的数据 |
| | | for (PledgeContract pledgeContract : pledgeContracts) { |
| | | if(pledgeContract.getDepotIds().contains(data.getDepotId())){ |
| | | if(pledgeContract.getStatus().equals(Constant.YN_N)){ |
| | | return "出库仓库未解压,无法保存!"; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //如果出库通知单类型为监管通知单 |
| | | if("20".equals(data.getType())){ |
| | | //1.验证银行是否填写,未填写,则不允许保存 |
| | | if(StringUtils.isEmpty(data.getBankId())){ |
| | | return "监督银行不能为空!"; |
| | | |
| | | } |
| | | //2.验证银行和仓库的对应关系是否正确,不正确则不允许保存 |
| | | //在质押合同找到未解压,且质押仓库包含当前仓库的 银行-仓库(质押合同关系) |
| | | Map<String, PledgeContract> bankDepotMap = new HashMap<>(); |
| | | for (PledgeContract pledgeContract : pledgeContracts) { |
| | | if(pledgeContract.getDepotIds().contains(data.getDepotId())){ |
| | | if(pledgeContract.getStatus().equals(Constant.YN_N)){ |
| | | bankDepotMap.put(pledgeContract.getPledgeBank(), pledgeContract); |
| | | } |
| | | } |
| | | } |
| | | //在map中寻找匹配银行的数据,如果没有匹配的数据,则不允许保存 |
| | | if(!bankDepotMap.containsKey(data.getBankId())){ |
| | | return "未找到对应的质押合同,请检查监督银行或者出库仓库填写是否正确!"; |
| | | |
| | | } |
| | | } |
| | | |
| | | if (null == data.getUpdateBy()) { |
| | | data.setUpdateBy(ContextUtil.getLoginUserName()); |
| | | data.setUpdateTime(new Date()); |
| | | data.setCreateBy(ContextUtil.getLoginUserName()); |
| | | data.setCreateTime(new Date()); |
| | | data.setAuditStatus(Constant.COMPLETE_STATUS_NONE); |
| | | data.setAuditStatus(AuditStatus.STATUS_10.getCode()); |
| | | data.setCompleteStatus(Constant.COMPLETE_STATUS_NONE); |
| | | noticeOutMapper.insert(data); |
| | | } else { |
| | | data.setUpdateBy(ContextUtil.getLoginUserName()); |
| | | data.setUpdateTime(new Date()); |
| | | noticeOutMapper.updateById(data); |
| | | } |
| | | data.setUpdateBy(ContextUtil.getLoginUserName()); |
| | | data.setUpdateTime(new Date()); |
| | | noticeOutRepository.save(data); |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * JPA - 删除数据 |
| | | * 删除数据 |
| | | * |
| | | * @param data |
| | | * @return |
| | | */ |
| | | public String delDataOut(InoutNoticeOut data) { |
| | | noticeOutRepository.delete(data); |
| | | noticeOutMapper.deleteById(data); |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * JPA - 根据ID获取通知单信息 |
| | | * 根据ID获取通知单信息 |
| | | * @param id |
| | | * @param type |
| | | * @return |
| | |
| | | } |
| | | NoticeDto noticeDto = new NoticeDto(); |
| | | if (Constant.TYPE_IN.equals(type)) { |
| | | InoutNoticeIn noticeIn = noticeInRepository.getDataById(ContextUtil.getCompanyId(), ContextUtil.subDeptId(null), id); |
| | | InoutNoticeIn noticeIn = this.getNoticeInOne(id); |
| | | BeanUtils.copyProperties(noticeIn, noticeDto); |
| | | } else { |
| | | InoutNoticeOut noticeOut = noticeOutRepository.getDataById(ContextUtil.getCompanyId(), ContextUtil.subDeptId(null), id); |
| | | InoutNoticeOut noticeOut = this.getNoticeOutOne(id); |
| | | BeanUtils.copyProperties(noticeOut, noticeDto); |
| | | } |
| | | return noticeDto; |
| | |
| | | * @return |
| | | */ |
| | | public String reSumNoticeInComplete(NoticeParam param) { |
| | | //TODO 待实现,后续根据需求进行实现 |
| | | if (StringUtils.isEmpty(param.getCustomerName())) { |
| | | return "客户编码为空!"; |
| | | } |
| | |
| | | if (StringUtils.isEmpty(param.getDeptId())) { |
| | | param.setDeptId(ContextUtil.subDeptId(null)); |
| | | } |
| | | noticeMapper.reSumNoticeInComplete(param); |
| | | return null; |
| | | } |
| | | |
| | |
| | | for (InoutNoticeOut noticeOut : noticeOutList) { |
| | | |
| | | param = new NoticeParam(noticeOut.getCompanyId(), noticeOut.getDeptId(), noticeOut.getDepotId(), |
| | | noticeOut.getCustomerId(), noticeOut.getFoodVariety(), noticeOut.getId()); |
| | | noticeOut.getCustomerName(), noticeOut.getFoodVariety(), noticeOut.getId()); |
| | | |
| | | log.info("开始更新出库通知单={}", param.toString()); |
| | | |
| | |
| | | * @return |
| | | */ |
| | | public String reSumNoticeOutComplete(NoticeParam param) { |
| | | //TODO 待实现,后续根据需求进行实现 |
| | | if (StringUtils.isEmpty(param.getCustomerName())) { |
| | | return "客户编码为空!"; |
| | | } |
| | |
| | | if (StringUtils.isEmpty(param.getDeptId())) { |
| | | param.setDeptId(ContextUtil.subDeptId(null)); |
| | | } |
| | | noticeMapper.reSumNoticeOutComplete(param); |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @param param |
| | | * @return |
| | | */ |
| | | public ExportWordParam handleInData(ExportWordParam param) { |
| | | |
| | | InoutNoticeIn notice = this.getNoticeInOne(param.getBizId()); |
| | | |
| | | //转换为模板需要的map数据源 |
| | | Map<String, Object> map = new HashMap(); |
| | | |
| | | map.put("serId", notice.getId()); |
| | | map.put("name", notice.getName()); |
| | | |
| | | String type = ""; |
| | | if("10".equals(notice.getType())){ |
| | | type = "库区通知单"; |
| | | } |
| | | if("20".equals(notice.getType())){ |
| | | type = "监管通知单"; |
| | | } |
| | | map.put("type", type); |
| | | |
| | | map.put("customerName", notice.getCustomerName()); |
| | | |
| | | String unitName = ""; |
| | | Dept dept = coreDeptService.getDeptById(notice.getUnitName()); |
| | | if(dept != null){ |
| | | unitName = dept.getKqmc(); |
| | | } |
| | | map.put("unitName", unitName); |
| | | |
| | | Depot depot = depotService.getCacheDepot(notice.getCompanyId(), notice.getDepotId()); |
| | | String depotId = ""; |
| | | if(dept != null){ |
| | | depotId = depot.getName(); |
| | | } |
| | | map.put("depotId", depotId); |
| | | |
| | | map.put("year", notice.getYear()); |
| | | map.put("targetNumber", notice.getTargetNumber()); |
| | | map.put("completeNumber", notice.getCompleteNumber()); |
| | | map.put("completeStatus", notice.getCompleteStatus()); |
| | | map.put("contract", notice.getContract()); |
| | | map.put("remark", notice.getRemark()); |
| | | map.put("createUser", notice.getCreateBy()); |
| | | map.put("createTime", DateFormatUtils.format(notice.getCreateTime(), "yyyy-MM-dd HH:mm:ss")); |
| | | |
| | | param.setDataMap(map); |
| | | return param; |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @param param |
| | | * @return |
| | | */ |
| | | public ExportWordParam handleOutData(ExportWordParam param) { |
| | | |
| | | InoutNoticeOut notice = this.getNoticeOutOne(param.getBizId()); |
| | | |
| | | //转换为模板需要的map数据源 |
| | | Map<String, Object> map = new HashMap(); |
| | | |
| | | map.put("serId", notice.getId()); |
| | | map.put("name", notice.getName()); |
| | | |
| | | String type = ""; |
| | | if("10".equals(notice.getType())){ |
| | | type = "库区通知单"; |
| | | } |
| | | if("20".equals(notice.getType())){ |
| | | type = "监管通知单"; |
| | | } |
| | | map.put("type", type); |
| | | |
| | | map.put("customerName", notice.getCustomerName()); |
| | | |
| | | String unitName = ""; |
| | | Dept dept = coreDeptService.getDeptById(notice.getUnitName()); |
| | | if(dept != null){ |
| | | unitName = dept.getKqmc(); |
| | | } |
| | | map.put("unitName", unitName); |
| | | |
| | | Depot depot = depotService.getCacheDepot(notice.getCompanyId(), notice.getDepotId()); |
| | | String depotId = ""; |
| | | if(dept != null){ |
| | | depotId = depot.getName(); |
| | | } |
| | | map.put("depotId", depotId); |
| | | |
| | | map.put("year", notice.getYear()); |
| | | map.put("targetNumber", notice.getTargetNumber()); |
| | | map.put("completeNumber", notice.getCompleteNumber()); |
| | | map.put("completeStatus", notice.getCompleteStatus()); |
| | | map.put("contract", notice.getContract()); |
| | | map.put("remark", notice.getRemark()); |
| | | map.put("createUser", notice.getCreateBy()); |
| | | map.put("createTime", DateFormatUtils.format(notice.getCreateTime(), "yyyy-MM-dd HH:mm:ss")); |
| | | |
| | | param.setDataMap(map); |
| | | return param; |
| | | } |
| | | |
| | | } |