PlannerServiceImpl.java 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package com.fuzamei.service.serviceImpl;
  2. import java.util.List;
  3. import java.util.Map;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.stereotype.Service;
  6. import org.springframework.transaction.annotation.Transactional;
  7. import com.alibaba.fastjson.JSON;
  8. import com.fuzamei.constant.OperationType;
  9. import com.fuzamei.constant.Roles;
  10. import com.fuzamei.entity.PlannerSupplier;
  11. import com.fuzamei.entity.User;
  12. import com.fuzamei.mapperInterface.PlannerMapper;
  13. import com.fuzamei.mapperInterface.ReceivingClerkMapper;
  14. import com.fuzamei.mapperInterface.UserMapper;
  15. import com.fuzamei.service.PlannerService;
  16. import com.fuzamei.util.blockchain.BlockChainUtil;
  17. import com.fuzamei.util.blockchain.ProtobufBean;
  18. @Service
  19. public class PlannerServiceImpl implements PlannerService{
  20. @Autowired
  21. private PlannerMapper plannerMapper;
  22. @Autowired
  23. private UserMapper userMapper;
  24. @Autowired
  25. private BlockChainUtil blockChainUtil;
  26. @Override
  27. public List<User> queryPlanner(Map<String, Object> map) {
  28. return plannerMapper.queryPlanner(map);
  29. }
  30. @Override
  31. public List<User> queryAllSupplierByPlannerId(int plannerId) {//根据计划员id查询已经有的供应商
  32. return plannerMapper.queryAllSupplierByPlannerId(plannerId);
  33. }
  34. @Override
  35. public List<User> queryAllNoSupplierByPlannerId(int plannerId) {////根据计划员id查询未添加的供应商
  36. return plannerMapper.queryAllNoSupplierByPlannerId(plannerId);
  37. }
  38. @Override
  39. @Transactional(rollbackFor=Exception.class)
  40. public void deleteBeforeSupplierByUserId(int plannerId) {//根据计划员id删除之前所有的供应商
  41. plannerMapper.deleteBeforeSupplierByUserId(plannerId);
  42. }
  43. @Override
  44. @Transactional(rollbackFor=Exception.class)
  45. public void insertAgainSupplier(User pp) {//得到前端传来所有得供应商ID 做插入操作
  46. String supplierIds = pp.getSupplierId();//前端传来的供应商id(格式1111,111,111,111)
  47. deleteBeforeSupplierByUserId(Integer.parseInt(pp.getPlannerId()));//删除计划员下面的所有供应商
  48. if(supplierIds==null||"".equals(supplierIds)){
  49. //下面是【循环添加供应商得id】
  50. pp.setSupplierIds(supplierIds.split(","));
  51. plannerMapper.insertAgainSupplier(pp);
  52. }
  53. //下面往【操作记录】表插入数据
  54. Long currentTime = System.currentTimeMillis();//得到当前系统时间
  55. String sign = pp.getSign();
  56. @SuppressWarnings("unchecked")
  57. Map<String,Object> map = JSON.parseObject(sign, Map.class);
  58. String hash = (String) map.get("sid");
  59. pp.setUserId(pp.getUserId());//操作人(管理员)
  60. pp.setOperationTypeId(OperationType.EDIT);//操作类型 (编辑配置后在添加)
  61. pp.setUserIdb(Integer.parseInt(pp.getPlannerId()));//这里是被操作人账号
  62. pp.setOperationTime(currentTime);//操作时间
  63. pp.setHash(hash);//操作hash
  64. userMapper.insertOperationHistory(pp);//插入到操作记录表去
  65. /* ProtobufBean protobufBean = blockChainUtil.getProtobufBean(pp.getSign());
  66. String result = blockChainUtil.sendPostParam(protobufBean);
  67. boolean flag = blockChainUtil.vilaResult(result);*/
  68. boolean flag = blockChainUtil.sendBlockChain(pp.getSign());//发送签名直接转发到区块链
  69. if(!flag) {
  70. throw new RuntimeException("区块链操作失败:");
  71. }
  72. }
  73. }