package com.example.erp.service.mm; import com.baomidou.dynamic.datasource.annotation.DS; import com.example.erp.entity.mm.MaterialStore; import com.example.erp.entity.userInfo.SysError; import com.example.erp.mapper.mm.BasicWarehouseTypeMapper; import com.example.erp.mapper.mm.MaterialInventoryMapper; import com.example.erp.mapper.mm.MaterialStoreMapper; import com.example.erp.service.userInfo.SysErrorService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.interceptor.TransactionAspectSupport; import java.text.DecimalFormat; import java.util.*; @Service @DS("mm") @Transactional(rollbackFor = Exception.class) public class MaterialStoreService { @Autowired MaterialStoreMapper materialStoreMapper; @Autowired MaterialInventoryMapper materialInventoryMapper; @Autowired BasicWarehouseTypeMapper basicWarehouseTypeMapper; @Autowired SysErrorService sysErrorService; public Boolean saveMaterialStore(Map object) { boolean saveState = true; String id = ""; String type = ""; String json = ""; double width = 0.0; double height = 0.0; double singlePieceArea=0.0; if (object.get("id") != null) { id = object.get("id").toString(); } if (object.get("type") != null) { type = object.get("type").toString(); } if (object.get("json") != null) { json = object.get("json").toString(); } if (object.get("width") != null) { width = Double.parseDouble(object.get("width").toString()); } if (object.get("height") != null) { height = Double.parseDouble(object.get("height").toString()); } DecimalFormat decimalFormat = new DecimalFormat("#0.00"); singlePieceArea= Double.parseDouble(decimalFormat.format(width * height / 100000)); if(Long.parseLong(id)>0){ materialStoreMapper.updateMaterialStore(type,json, Long.valueOf(id)); if (Objects.equals(type, "原片")){ materialInventoryMapper.updateMaterialInventoryArea(Long.valueOf(id),singlePieceArea); } }else{ materialStoreMapper.insertMaterialStore(type,json); } return saveState; } public Map getSelectMaterialStore(Integer pageNum, Integer pageSize, MaterialStore materialStore) { Integer offset = (pageNum - 1) * pageSize; Map map = new HashMap<>(); map.put("data", materialStoreMapper.getSelectMaterialStore(offset, pageSize, materialStore)); map.put("total", materialStoreMapper.getSelectMaterialStorePageTotal(offset, pageSize, materialStore)); return map; } public Boolean deleteMaterialStore(Map object) { boolean saveState = true; //设置回滚点 Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint(); try { String id = ""; if (object.get("id") != null) { id = object.get("id").toString(); } if(id!=null){ materialStoreMapper.deleteMaterialStore(Long.valueOf(id)); } } catch (Exception e) { TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint); //将异常传入数据库 SysError sysError = new SysError(); sysError.setError(e.toString()); sysError.setFunc("saveOrder"); sysErrorService.insert(sysError); saveState = false; } return saveState; } }