| | |
| | | package com.dy.pmsProduct.order; |
| | | |
| | | import cn.hutool.core.codec.Base64; |
| | | import com.dy.common.webFilter.UserTokenContext; |
| | | import com.dy.common.webUtil.QueryResultVo; |
| | | import com.dy.pmsGlobal.daoOth.OthFileMapper; |
| | | import com.dy.pmsGlobal.daoPr.*; |
| | | import com.dy.pmsGlobal.dyFile.FileOperate; |
| | | import com.dy.pmsGlobal.pojoBa.BaUser; |
| | | import com.dy.pmsGlobal.pojoPlt.PltProduct; |
| | | import com.dy.pmsGlobal.pojoPr.*; |
| | | import com.dy.pmsGlobal.util.UserUtil; |
| | | import com.dy.pmsProduct.order.QueryVo; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.dubbo.common.utils.PojoUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | |
| | | private PrOrderMapper orderDao; |
| | | private PrOrderItemMapper orderItemDao; |
| | | private UserUtil userUtil; |
| | | private FileOperate fileOperate; |
| | | private OthFileMapper othFileMapper; |
| | | @Value("${dy.webFile.fmUrl}") |
| | | private String fmUrl; |
| | | |
| | | @Autowired |
| | | public void setOrderDao(PrOrderMapper orderDao) { |
| | | this.orderDao = orderDao; |
| | |
| | | public void setUserUtil(UserUtil userUtil) { |
| | | this.userUtil = userUtil; |
| | | } |
| | | |
| | | @Autowired |
| | | public void setFileOperate(FileOperate fileOperate) { |
| | | this.fileOperate = fileOperate; |
| | | } |
| | | |
| | | @Autowired |
| | | public void setOthFileMapper(OthFileMapper othFileMapper) { |
| | | this.othFileMapper = othFileMapper; |
| | | } |
| | | |
| | | @Transactional |
| | | public int save(PrOrder p) { |
| | | p.id = null; |
| | |
| | | } |
| | | p.setDeleted(false); |
| | | BaUser loginUser = userUtil.getUser(UserTokenContext.get()); |
| | | if(loginUser!=null){ |
| | | if (loginUser != null) { |
| | | p.creator = loginUser.id; |
| | | } |
| | | int count = orderDao.insertSelective(p); |
| | | saveOrderItems(p); |
| | | return count; |
| | | } |
| | | |
| | | @Transactional |
| | | public int update(PrOrder p) { |
| | | if (orderDao.exists(p.name, p.id)) { |
| | | throw new RuntimeException("订单名称不能重复"); |
| | | } |
| | | int count = orderDao.updateByPrimaryKeySelective(p); |
| | | saveOrderItems(p); |
| | | if (count > 0) { |
| | | saveOrderItems(p); |
| | | } |
| | | return count; |
| | | } |
| | | |
| | | private void saveOrderItems(PrOrder p) { |
| | | p.items.forEach(param->{ |
| | | param.orderId=p.id; |
| | | if(param.id !=null){ |
| | | p.items.forEach(param -> { |
| | | param.orderId = p.id; |
| | | if (param.id != null) { |
| | | orderItemDao.updateByPrimaryKeySelective(param); |
| | | }else{ |
| | | param.deleted=false; |
| | | } else { |
| | | param.deleted = false; |
| | | orderItemDao.insert(param); |
| | | } |
| | | }); |
| | |
| | | |
| | | /** |
| | | * 逻辑删除实体 |
| | | * |
| | | * @param id 实体ID |
| | | * @return 影响记录数量 |
| | | */ |
| | |
| | | } |
| | | |
| | | public PrOrder selectById(String proId) { |
| | | PrOrder pro=orderDao.selectByPrimaryKey(Long.valueOf(proId)); |
| | | PrOrder pro = orderDao.selectByPrimaryKey(Long.valueOf(proId)); |
| | | changeRate(pro); |
| | | return pro; |
| | | } |
| | | |
| | |
| | | //计算分页等信息 |
| | | rsVo.calculateAndSet(itemTotal, params); |
| | | |
| | | List<PrOrder> orderList = orderDao.selectSome(params); |
| | | for (PrOrder prOrder : orderList) { |
| | | changeRate(prOrder); |
| | | } |
| | | //查询符合条件的记录 |
| | | rsVo.obj = orderDao.selectSome(params); |
| | | rsVo.obj = orderList; |
| | | return rsVo; |
| | | } |
| | | |
| | | private void changeRate(PrOrder prOrder) { |
| | | List<PrOrderItem> items = prOrder.items; |
| | | for (int i = 1; i < items.size(); i++) { |
| | | for (int j = i - 1; j >= 0; j--) { |
| | | //拿着i依次跟上一个比较,如果产品相同,则上一个记录complete_number - number 如果 > 0 分给i ,如果 < 0 则将 complete_number 置为0 |
| | | if (items.get(j).getProId().intValue() == items.get(i).getProId().intValue()) { |
| | | int remainNumber = items.get(j).getCompleteNumber() - items.get(j).getNumber(); |
| | | if (remainNumber > 0) { |
| | | items.get(j).setCompleteNumber(items.get(j).getNumber()); |
| | | items.get(j).setCompleteRate("100.00%"); |
| | | items.get(i).setCompleteNumber(remainNumber); |
| | | BigDecimal remainBig = new BigDecimal(remainNumber * 100); |
| | | BigDecimal iNumberBig = new BigDecimal(items.get(i).getNumber()); |
| | | BigDecimal result = remainBig.divide(iNumberBig, 2, RoundingMode.HALF_UP); |
| | | items.get(i).setCompleteRate(result.toString() +"%"); |
| | | }else{ |
| | | items.get(i).setCompleteNumber(0); |
| | | items.get(i).setCompleteRate("0.00%"); |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | public List<PrOrder> selectAll(QueryVo queryVo) { |
| | | Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo); |
| | | return orderDao.selectAll(params); |
| | | List<PrOrder> orderList = orderDao.selectAll(params); |
| | | for (PrOrder prOrder : orderList) { |
| | | changeRate(prOrder); |
| | | } |
| | | return orderList; |
| | | } |
| | | } |