| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- package com.jeesite.modules.mes.service;
- import java.util.List;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import com.jeesite.common.entity.Page;
- import com.jeesite.common.service.CrudService;
- import com.jeesite.common.mybatis.mapper.query.QueryType;
- import com.jeesite.modules.mes.entity.MesInbound;
- import com.jeesite.modules.mes.dao.MesInboundDao;
- import com.jeesite.common.service.ServiceException;
- import com.jeesite.common.config.Global;
- import com.jeesite.common.validator.ValidatorUtils;
- import com.jeesite.common.utils.excel.ExcelImport;
- import org.springframework.web.multipart.MultipartFile;
- import javax.validation.ConstraintViolation;
- import javax.validation.ConstraintViolationException;
- /**
- * 入库表Service
- * @author system
- * @version 2026-05-09
- */
- @Service
- public class MesInboundService extends CrudService<MesInboundDao, MesInbound> {
-
- /**
- * 获取单条数据
- * @param mesInbound
- * @return
- */
- @Override
- public MesInbound get(MesInbound mesInbound) {
- return super.get(mesInbound);
- }
-
- /**
- * 查询分页数据
- * @param mesInbound 查询条件
- * @param mesInbound.page 分页对象
- * @return
- */
- @Override
- public Page<MesInbound> findPage(MesInbound mesInbound) {
- return super.findPage(mesInbound);
- }
-
- /**
- * 查询列表数据
- * @param mesInbound
- * @return
- */
- @Override
- public List<MesInbound> findList(MesInbound mesInbound) {
- return super.findList(mesInbound);
- }
-
- /**
- * 保存数据(插入或更新)
- * @param mesInbound
- */
- @Override
- @Transactional
- public void save(MesInbound mesInbound) {
- super.save(mesInbound);
- }
- /**
- * 导入数据
- * @param file 导入的数据文件
- */
- @Transactional
- public String importData(MultipartFile file) {
- if (file == null){
- throw new ServiceException(text("请选择导入的数据文件!"));
- }
- int successNum = 0; int failureNum = 0;
- StringBuilder successMsg = new StringBuilder();
- StringBuilder failureMsg = new StringBuilder();
- try(ExcelImport ei = new ExcelImport(file, 2, 0)){
- List<MesInbound> list = ei.getDataList(MesInbound.class);
- for (MesInbound mesInbound : list) {
- try{
- ValidatorUtils.validateWithException(mesInbound);
- this.save(mesInbound);
- successNum++;
- successMsg.append("<br/>" + successNum + "、编号 " + mesInbound.getId() + " 导入成功");
- } catch (Exception e) {
- failureNum++;
- String msg = "<br/>" + failureNum + "、编号 " + mesInbound.getId() + " 导入失败:";
- if (e instanceof ConstraintViolationException){
- ConstraintViolationException cve = (ConstraintViolationException)e;
- for (ConstraintViolation<?> violation : cve.getConstraintViolations()) {
- msg += Global.getText(violation.getMessage()) + " ("+violation.getPropertyPath()+")";
- }
- }else{
- msg += e.getMessage();
- }
- failureMsg.append(msg);
- logger.error(msg, e);
- }
- }
- } catch (Exception e) {
- logger.error(e.getMessage(), e);
- failureMsg.append(e.getMessage());
- return failureMsg.toString();
- }
- if (failureNum > 0) {
- failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
- throw new ServiceException(failureMsg.toString());
- }else{
- successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
- }
- return successMsg.toString();
- }
-
- /**
- * 更新状态
- * @param mesInbound
- */
- @Override
- @Transactional
- public void updateStatus(MesInbound mesInbound) {
- super.updateStatus(mesInbound);
- }
-
- /**
- * 删除数据
- * @param mesInbound
- */
- @Override
- @Transactional
- public void delete(MesInbound mesInbound) {
- super.delete(mesInbound);
- }
- /**
- * 统计指定产线、指定时间段内的入库数量(用于大屏“近七日产品质检”的产出统计)
- * @param lineSn 产线编码(MP/XT/ZP)
- * @param sdate 开始时间(含)yyyy-MM-dd HH:mm:ss
- * @param edate 结束时间(不含)yyyy-MM-dd HH:mm:ss
- */
- public Long countByLineAndDate(String lineSn, String sdate, String edate){
- MesInbound q = new MesInbound();
- q.getSqlMap().getWhere()
- .and("line_sn", QueryType.EQ, lineSn)
- .and("create_date", QueryType.GTE, sdate)
- .and("create_date", QueryType.LT, edate);
- return super.findCount(q);
- }
-
- }
|