package com.steerinfo.dil.service.impl; import com.steerinfo.dil.mapper.DilNoticeMapper; import com.steerinfo.dil.model.DilNotice; import com.steerinfo.dil.service.IDilNoticeService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import java.util.*; import java.math.BigDecimal; /** * DilNotice服务实现: * @author generator * @version 1.0-SNAPSHORT 2021-12-08 02:21 * 类描述 * 修订历史: * 日期:2021-12-08 * 作者:generator * 参考: * 描述:DilNotice服务实现 * @see null * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved. */ @Service(value = "dilNoticeService") public class DilNoticeServiceImpl implements IDilNoticeService { @Autowired private DilNoticeMapper dilNoticeMapper; /** * 获取通知信息 * */ @Override public List> getNoticeList(Map mapVal) { return dilNoticeMapper.getNoticeList(mapVal); } /** * 承运商获取通知信息 * */ @Override public List> getCarrierNoticeList(Map mapVal) { List> mapList=dilNoticeMapper.getCarrierNoticeList(mapVal); for (Map map : mapList) { if ("1".equals(map.get("status"))){ //有历史数据(替换) map.put("noticeTitle",map.get("updateTitle")); map.put("noticeContent",map.get("updateContent")); map.put("insertUsername",map.get("updateUsername")); map.put("insertTime",map.get("updateTime")); } } return mapList; } /** * 销售公司获取通知信息 * */ @Override public List> getMarketingNoticeList(Map mapVal) { List> mapList=dilNoticeMapper.getMarketingNoticeList(mapVal); for (Map map : mapList) { if ("1".equals(map.get("status"))){ //有历史数据(替换) map.put("noticeTitle",map.get("updateTitle")); map.put("noticeContent",map.get("updateContent")); map.put("insertUsername",map.get("updateUsername")); map.put("insertTime",map.get("updateTime")); } } return mapList; } /** * 收货用户获取通知信息 * */ @Override public List> getClientNoticeList(Map mapVal) { List> mapList= dilNoticeMapper.getClientNoticeList(mapVal); for (Map map : mapList) { if ("1".equals(map.get("status"))){ //有历史数据(替换) map.put("noticeTitle",map.get("updateTitle")); map.put("noticeContent",map.get("updateContent")); map.put("insertUsername",map.get("updateUsername")); map.put("insertTime",map.get("updateTime")); } } return mapList; } @Override public List> getNewNoticeByPermission(BigDecimal permission) { return dilNoticeMapper.getNewNoticeByPermission(permission); } /** * 增加通知信息 * */ @Override /*这里是解决前端毛病所妥协的结果,前端拿不到value值,只能拿到name也就是key值,这里在后端强行将key转为value值QAQ*/ public int insertNotice(DilNotice dilNotice) { int result=0; dilNotice.setDeleted(new BigDecimal(0)); dilNotice.setInsertTime(dilNotice.getInsertTime()); dilNotice.setNoticeId(dilNoticeMapper.selectNoticeId()); dilNotice.setStatus("0"); if(dilNotice.getPermissions()!=null){ if(dilNotice.getPermissions().equals("承运商")){ dilNotice.setPermission("chengyunshang"); } else if(dilNotice.getPermissions().equals("销售公司")){ dilNotice.setPermission("wuliuyunshubu"); } else if(dilNotice.getPermissions().equals("收货客户")){ dilNotice.setPermission("shouhuokehu"); }else{ dilNotice.setPermission("qita"); /*dilNoticeMapper.insertSelective(dilNotice); result +=dilNoticeMapper.insertIntoNoticeUser1(dilNotice); return result;*/ } } //需要手动设置发布人 /*dilNotice.setInsertUsername("admin");*/ result+=dilNoticeMapper.insertSelective(dilNotice); /*if (result==0){ dilNoticeMapper.insertIntoNoticeUser(dilNotice); }*/ return result; } /** * @author:zyf * @version:2.0 * @Date:2022-10-14 * @Description:发布通知 */ @Override public int releaseNotice(DilNotice dilNotice) { //发布通知 //1.先判断permission是否有值 //2.看notice有无历史的修改数据 //3.发布 int result=0; //发布的通知 DilNotice dilNotice2=new DilNotice(); if (dilNotice.getPermission()!=null){ //查询是否有历史修改数据 DilNotice dilNotice1 = dilNoticeMapper.gethistoryorgCode(dilNotice.getNoticeId()); //历史数据有值与否(1为有值,0为没有值) if ("1".equals(dilNotice1.getStatus())){ dilNoticeMapper.deleteNoticeUsers(dilNotice.getNoticeId()); //1.判断时间是否需要修改(1.1) Date updateTime = dilNotice1.getUpdateTime(); if (updateTime.compareTo(new Date())>0){ //时间大于当前时间的不动 dilNotice2.setInsertTime(updateTime); }else { //时间小于等于当前时间的,时间变为当前时间 dilNotice2.setInsertTime(new Date()); } //历史数据 dilNotice2.setNoticeId(dilNotice.getNoticeId()); dilNotice2.setNoticeTitle(dilNotice1.getUpdateTitle()); dilNotice2.setNoticeContent(dilNotice1.getUpdateContent()); dilNotice2.setInsertUsername(dilNotice1.getUpdateUsername()); dilNoticeMapper.updatehistorydata(dilNotice2); if ("qita".equals(dilNotice.getPermission())){ //全部要单独 result+=dilNoticeMapper.insertIntoNoticeUser1(dilNotice); }else { result+=dilNoticeMapper.insertIntoNoticeUser(dilNotice); } }else { //判断时间是否需要修改(1.2) Date insertTime =dilNotice.getInsertTime(); dilNoticeMapper.deleteNoticeUsers(dilNotice.getNoticeId()); if (insertTime.compareTo(new Date())>0){ //时间大于当前时间的不动 dilNotice2.setInsertTime(dilNotice.getInsertTime()); }else { //时间小于等于当前时间的,时间变为当前时间 dilNotice2.setInsertTime(new Date()); } dilNotice2.setNoticeId(dilNotice.getNoticeId()); dilNoticeMapper.updateTime(dilNotice2); if ("qita".equals(dilNotice.getPermission())){ //全部要单独 result+=dilNoticeMapper.insertIntoNoticeUser1(dilNotice); }else { result+=dilNoticeMapper.insertIntoNoticeUser(dilNotice); } } }else { return 0; } return result; } /** * 修改通知信息 * */ @Override public int updateNotice(DilNotice dilNotice) { dilNotice.setUpdateTime(new Date()); //存储修改过后的内容 DilNotice dilNotice1=new DilNotice(); dilNotice.setUpdateUsername("admin"); if ("承运商".equals(dilNotice.getPermission())){ dilNotice1.setPermission("chengyunshang"); }else if ("销售公司".equals(dilNotice.getPermission())){ dilNotice1.setPermission("wuliuyunshubu"); }else if ("收货客户".equals(dilNotice.getPermission())){ dilNotice1.setPermission("shouhuokehu"); }else { dilNotice1.setPermission("qita"); } String code = dilNoticeMapper.getorgCode(dilNotice.getNoticeId()); dilNotice1.setUpdateTitle(dilNotice.getNoticeTitle()); dilNotice1.setUpdateContent(dilNotice.getNoticeContent()); dilNotice1.setUpdateTime(dilNotice.getInsertTime()); dilNotice1.setUpdateUsername(dilNotice.getInsertUsername()); dilNotice1.setStatus("1"); dilNotice1.setNoticeId(dilNotice.getNoticeId()); return dilNoticeMapper.modifyData(dilNotice1); } /** * @author:zyf * @version:1.0 * @Date:2022-09-24 * @Description:修改用户通知的相关信息 */ @Override public int updateNoticeStatus(String userId,int noticeId) { dilNoticeMapper.updatestatus(userId,noticeId); return dilNoticeMapper.gettaskAllNum(userId); } /** * 删除通知信息 * */ @Override public int deleteNotice(BigDecimal id) { DilNotice dilNotice = dilNoticeMapper.selectByPrimaryKey(id); dilNotice.setDeleted(new BigDecimal(1)); //删除中间表信息 dilNoticeMapper.deleteNoticeUsers(id); //删除通知表的数据 return dilNoticeMapper.deleteNotice(id); } //根据用户ID获取用户名字 @Override public String queryName(String userId) { return dilNoticeMapper.queryName(userId); } /** * 根据id获取运力信息 * @param id * @return */ @Override public List> getNoticeById(BigDecimal id) { String status = dilNoticeMapper.getStatus(id); if ("1".equals(status)){ return dilNoticeMapper.getNoticeById1(id); }else { return dilNoticeMapper.getNoticeById(id); } } /** * @author:zyf * @version:1.0 * @Date: * @Description: 获取通知信息数据 */ public List> getNoticeData(String userId){ List> noticeData=new ArrayList<>(); /*if ("chengyunshang".equals(orgcode)){ BigDecimal permission=BigDecimal.valueOf(1); noticeData = dilNoticeMapper.getNoticeData(permission); }else if ("xiaoshougongsi".equals(orgcode)){ BigDecimal permission=BigDecimal.valueOf(2); noticeData = dilNoticeMapper.getNoticeData(permission); }else if ("shouhuokehu".equals(orgcode)){ BigDecimal permission=BigDecimal.valueOf(3); noticeData = dilNoticeMapper.getNoticeData(permission); }else { noticeData = dilNoticeMapper.getNoticeData1(); }*/ return dilNoticeMapper.getNoticeData(userId); } /* * 获取下拉框 * */ /* @Override public List> getCapacityTypeId() { return rmsCapacityMapper.getCapacityTypeId(); } @Override public List> getCarrierId() { return rmsCapacityMapper.getCarrierId(); } */ @Override public List> getNoticeAll(Map mapValue) { return dilNoticeMapper.getNoticeAll(mapValue); } @Override public int readAll(Map map) { return dilNoticeMapper.readAll(map); } @Override public List> getNoticeUser(Map mapValue) { return dilNoticeMapper.getNoticeUser(mapValue); } /** * 查询国内矿采购订单是否符合标准,若不符合则发送给自动化部负责人:(UserId:1012690778083954688) */ @Scheduled(fixedRate = 1000*60*60) public void checkPurchaseOrder(){ List> purchaseOrders=dilNoticeMapper.findErrorOrder(); for(Map item:purchaseOrders){ //插入通知表 DilNotice notice=new DilNotice(); notice.setNoticeId(dilNoticeMapper.selectNoticeId()); notice.setNoticeTitle(item.get("purchaseOrderNo")+"订单异常"); notice.setNoticeContent("国内矿订单'"+item.get("purchaseOrderNo")+"'缺少发站!"); notice.setInsertTime(new Date()); notice.setInsertUsername("system"); notice.setDeleted(new BigDecimal(0)); notice.setInsertUpdateRemark(""+item.get("purchaseOrderNo")); dilNoticeMapper.insertSelective(notice); //插入通知子表 item.put("noticeId",notice.getNoticeId()); item.put("userId","1012690778083954688"); dilNoticeMapper.insertIntoNoticeUserToOne(item); } } }