| | |
| | | package com.dy.pmsPlatform.product; |
| | | |
| | | import com.alibaba.excel.util.StringUtils; |
| | | import com.dy.common.webUtil.QueryResultVo; |
| | | import com.dy.pmsGlobal.daoOth.OthFileMapper; |
| | | import com.dy.pmsGlobal.daoPlt.PltProParamsMapper; |
| | |
| | | import com.dy.pmsGlobal.pojoOth.OthFile; |
| | | import com.dy.pmsGlobal.pojoPlt.PltProduct; |
| | | import com.dy.pmsGlobal.pojoPlt.PltProductFile; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | 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.dao.DuplicateKeyException; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | |
| | | @Value("${dy.webFile.fmUrl}") |
| | | private String fmUrl ; |
| | | |
| | | private static final String DEFAULT_CODE = "001"; |
| | | private static final String CODE_FORMAT = "%03d"; |
| | | |
| | | @Autowired |
| | | public void setFileOperate(FileOperate fileOperate){ |
| | |
| | | |
| | | @Transactional |
| | | public int save(PltProduct p) { |
| | | int count = dao.insert(p); |
| | | if(count>0){ |
| | | saveProRel(p); |
| | | } |
| | | return count; |
| | | int flag=0; |
| | | do { |
| | | p.code = getNextCode(); |
| | | try { |
| | | int count = dao.insertSelective(p); |
| | | if (count > 0) { |
| | | saveProRel(p); |
| | | return count; |
| | | } |
| | | } catch (DuplicateKeyException e) { |
| | | // 如果出现唯一约束违反异常,尝试获取新的code并重试 |
| | | log.warn("插入产品时遇到唯一约束异常,尝试获取新的code", e); |
| | | } |
| | | flag++; |
| | | } while (flag<5); |
| | | return 0; |
| | | } |
| | | private String getNextCode(){ |
| | | log.info("获取产品编号"); |
| | | String maxCode = dao.selectMaxCode(); |
| | | if (StringUtils.isBlank(maxCode)) { |
| | | return DEFAULT_CODE; |
| | | } else { |
| | | int nextCode = Integer.parseInt(maxCode) + 1; |
| | | // 检查溢出 |
| | | if (nextCode > 999) { |
| | | throw new RuntimeException("产品编号溢出"); |
| | | } |
| | | return String.format(CODE_FORMAT, nextCode); |
| | | } |
| | | } |
| | | |
| | | @Transactional |
| | | public int update(PltProduct p) { |
| | | int count = dao.updateByPrimaryKeySelective(p); |
| | |
| | | } |
| | | |
| | | |
| | | public List<PltProduct> selectAll(QueryVo queryVo) { |
| | | Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo); |
| | | return dao.selectAll(params); |
| | | } |
| | | |
| | | |
| | | public void downloadDoc(HttpServletResponse response) { |
| | | PltProduct pro=dao.selectByPrimaryKey(Long.valueOf(1)); |
| | | } |
| | | } |