New file |
| | |
| | | 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.Log; |
| | | 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.LogService; |
| | | 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; |
| | | @Autowired |
| | | LogService logService; |
| | | |
| | | public String saveMaterialStore(Map<String,Object> object) { |
| | | String saveState = "true"; |
| | | //设置回滚点 |
| | | Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint(); |
| | | try { |
| | | 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()); |
| | | } |
| | | |
| | | Log log = new Log(); |
| | | log.setOperatorId(object.get("userId").toString()); |
| | | log.setOperator(object.get("userName").toString()); |
| | | log.setContent(object.toString()); |
| | | |
| | | DecimalFormat decimalFormat = new DecimalFormat("#0.00"); |
| | | singlePieceArea= Double.parseDouble(decimalFormat.format(width * height / 100000)); |
| | | Integer jsonCount=materialStoreMapper.selectMaterialStoreJson(json); |
| | | if(jsonCount==0){ |
| | | if(Long.parseLong(id)>0){ |
| | | materialStoreMapper.updateMaterialStore(type,json, Long.valueOf(id)); |
| | | if (Objects.equals(type, "原片")){ |
| | | materialInventoryMapper.updateMaterialInventoryArea(Long.valueOf(id),singlePieceArea); |
| | | } |
| | | log.setFunction("saveMaterialStore修改"); |
| | | }else{ |
| | | materialStoreMapper.insertMaterialStore(type,json); |
| | | log.setFunction("saveMaterialStore新增"); |
| | | } |
| | | }else{ |
| | | saveState = "false1"; |
| | | } |
| | | logService.saveLog(log); |
| | | |
| | | } catch (Exception e) { |
| | | TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint); |
| | | //将异常传入数据库 |
| | | SysError sysError = new SysError(); |
| | | sysError.setError(e+Arrays.toString(e.getStackTrace())); |
| | | sysError.setFunc("saveMaterialStore"); |
| | | sysErrorService.insert(sysError); |
| | | saveState = "false"; |
| | | |
| | | } |
| | | return saveState; |
| | | |
| | | } |
| | | |
| | | public Map<String, Object> getSelectMaterialStore(Integer pageNum, Integer pageSize, MaterialStore materialStore) { |
| | | Integer offset = (pageNum - 1) * pageSize; |
| | | |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("data", materialStoreMapper.getSelectMaterialStore(offset, pageSize, materialStore)); |
| | | map.put("total", materialStoreMapper.getSelectMaterialStorePageTotal(offset, pageSize, materialStore)); |
| | | return map; |
| | | } |
| | | |
| | | public Map<String, Object> getSelectMaterialStores(MaterialStore materialStore) { |
| | | |
| | | |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("data", materialStoreMapper.getSelectMaterialStores(materialStore)); |
| | | return map; |
| | | } |
| | | |
| | | public String deleteMaterialStore(Map<String,Object> object) { |
| | | String saveState = "true"; |
| | | //设置回滚点 |
| | | Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint(); |
| | | try { |
| | | String id = ""; |
| | | if (object.get("id") != null) { |
| | | id = object.get("id").toString(); |
| | | } |
| | | if(id!=null){ |
| | | Integer materialCount=materialStoreMapper.selectMaterialStore(Long.valueOf(id)); |
| | | if(materialCount==0){ |
| | | materialStoreMapper.deleteMaterialStore(Long.valueOf(id)); |
| | | }else{ |
| | | saveState="false1"; |
| | | } |
| | | |
| | | } |
| | | Log log = new Log(); |
| | | log.setOperatorId(object.get("userId").toString()); |
| | | log.setOperator(object.get("userName").toString()); |
| | | log.setContent(object.toString()); |
| | | log.setFunction("deleteMaterialStore删除:"+id); |
| | | logService.saveLog(log); |
| | | |
| | | |
| | | |
| | | } catch (Exception e) { |
| | | TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint); |
| | | //将异常传入数据库 |
| | | SysError sysError = new SysError(); |
| | | sysError.setError(e+Arrays.toString(e.getStackTrace())); |
| | | sysError.setFunc("deleteMaterialStore"); |
| | | sysErrorService.insert(sysError); |
| | | saveState = "false"; |
| | | |
| | | } |
| | | return saveState; |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |