| | |
| | | package com.whyc.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.Wrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.whyc.mapper.WorkflowLinkMapper; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.mapper.WorkflowMainMapper; |
| | | import com.whyc.pojo.WorkflowAlarm; |
| | | import com.whyc.pojo.BattDischargePlanTemp; |
| | | import com.whyc.pojo.UserInf; |
| | | import com.whyc.pojo.WorkflowLink; |
| | | import com.whyc.pojo.WorkflowMain; |
| | | import com.whyc.util.ActionUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.ServletContext; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | public class WorkflowMainService { |
| | |
| | | @Resource |
| | | private WorkflowMainMapper mapper; |
| | | |
| | | @Resource |
| | | private WorkflowLinkMapper linkMapper; |
| | | @Autowired |
| | | private WorkflowLinkService linkService; |
| | | |
| | | public String getNextSequence() { |
| | | @Autowired |
| | | private BattDischargePlanTempService tempService; |
| | | |
| | | /** |
| | | * 分派单号: |
| | | * */ |
| | | public String getNextOrderId(String typeName) { |
| | | ServletContext application = ActionUtil.getApplication(); |
| | | List<String> orderIdList = (List) application.getAttribute("orderIdList"); |
| | | if(orderIdList == null){ |
| | | orderIdList = new LinkedList<>(); |
| | | } |
| | | String nextSequence = ""; |
| | | QueryWrapper<WorkflowMain> wrapper = Wrappers.query(); |
| | | |
| | | String orderId = "WF-1-"; |
| | | String orderId = "FG-"+typeName+"-"; |
| | | String ymd = new SimpleDateFormat("yyyyMMdd").format(new Date()); |
| | | orderId = orderId+ymd+"-"; |
| | | //先查询是否缓存中是否存在前缀相同的单号,有的话存起来 |
| | | List<Integer> sequenceList = new LinkedList<>(); |
| | | sequenceList.add(0); |
| | | for (String item : orderIdList) { |
| | | if(item.startsWith(orderId)){ |
| | | String sequence = item.split("-")[3]; |
| | | sequenceList.add(Integer.parseInt(sequence)); |
| | | } |
| | | } |
| | | wrapper.likeRight("order_id",orderId).orderByDesc("order_id").last(" limit 1"); |
| | | WorkflowMain workflowMain = mapper.selectOne(wrapper); |
| | | if(workflowMain == null){ |
| | | nextSequence="00001"; |
| | | }else{ |
| | | String maxSequence = workflowMain.getOrderId().split("-")[3]; |
| | | int nextSequenceIntValue = Integer.parseInt(maxSequence) + 1; |
| | | nextSequence = String.format("%05d", nextSequenceIntValue); |
| | | if(workflowMain != null){ |
| | | String sequence = workflowMain.getOrderId().split("-")[3]; |
| | | sequenceList.add(Integer.parseInt(sequence)); |
| | | } |
| | | return nextSequence; |
| | | Integer maxSequence = sequenceList.stream().max(Comparator.comparing(Integer::intValue)).get(); |
| | | nextSequence = String.format("%05d", maxSequence+1); |
| | | String nextOrderId = orderId + nextSequence; |
| | | //加入缓存中 |
| | | orderIdList.add(nextOrderId); |
| | | application.setAttribute("orderIdList",orderIdList); |
| | | return nextOrderId; |
| | | } |
| | | |
| | | |
| | | |
| | | public static void main(String[] args) { |
| | | int a = 110; |
| | | System.out.println(String.format("%05d",a)); |
| | | public void add(WorkflowMain main) { |
| | | mapper.insert(main); |
| | | } |
| | | |
| | | public void add(List<WorkflowMain> workflowMainList) { |
| | | public void addBatch(List<WorkflowMain> workflowMainList) { |
| | | mapper.insertBatchSomeColumn(workflowMainList); |
| | | } |
| | | |
| | | public PageInfo<WorkflowMain> getPendingWorkflowList(Long userId,Integer type,Integer pageNum,Integer pageSize,WorkflowMain main) { |
| | | PageHelper.startPage(pageNum,pageSize,true); |
| | | //获取系统生成,待处理的工单,获取正在工单节点表中待处理的工单 |
| | | List<WorkflowMain> workflowList = mapper.getPendingWorkflowList(userId,type,main); |
| | | PageInfo<WorkflowMain> pageInfo = new PageInfo<>(workflowList); |
| | | |
| | | return pageInfo; |
| | | } |
| | | |
| | | |
| | | public WorkflowMain getBaseInfo(Integer mainId) { |
| | | QueryWrapper<WorkflowMain> wrapper = Wrappers.query(); |
| | | wrapper.eq("id",mainId); |
| | | return mapper.selectOne(wrapper); |
| | | //根据mainId查询是哪种类型 |
| | | QueryWrapper<WorkflowMain> query = Wrappers.query(); |
| | | query.eq("id",mainId).last(" limit 1"); |
| | | WorkflowMain workflowMain = mapper.selectOne(query); |
| | | Integer type = workflowMain.getType(); |
| | | if(type ==1){ |
| | | List<BattDischargePlanTemp> tempList = tempService.getListByMainId(mainId); |
| | | workflowMain.setTempList(tempList); |
| | | } |
| | | List<WorkflowLink> linkList = linkService.getWorkflowInfo(mainId); |
| | | workflowMain.setLinkList(linkList); |
| | | |
| | | return workflowMain; |
| | | } |
| | | |
| | | public List<WorkflowLink> getAssignReply(Integer mainId) { |
| | |
| | | //return linkMapper. |
| | | return null; |
| | | } |
| | | |
| | | public void updateStatus(Integer id, Integer status,String endReason,Date endTime) { |
| | | WorkflowMain main = new WorkflowMain(id,status,endReason,endTime); |
| | | mapper.updateById(main); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @param userId |
| | | * @param type |
| | | * @see com.whyc.constant.WorkflowEnum |
| | | * |
| | | * @return |
| | | */ |
| | | public Response<Map<Integer,Integer>> getOwnStatistics(int userId, int type) { |
| | | Map<Integer,Integer> statistics = new HashMap<>(); |
| | | statistics.put(1,0); |
| | | statistics.put(2,0); |
| | | statistics.put(3,0); |
| | | QueryWrapper<WorkflowMain> query = Wrappers.query(); |
| | | query.eq("create_user_id",userId); |
| | | List<WorkflowMain> mains = mapper.selectList(query); |
| | | Map<Integer, List<WorkflowMain>> statusListMap = mains.stream().collect(Collectors.groupingBy(WorkflowMain::getStatus)); |
| | | Set<Integer> statusSet = statusListMap.keySet(); |
| | | for (Integer status : statusSet) { |
| | | statistics.put(status,statusListMap.get(status).size()); |
| | | } |
| | | return new Response<Map<Integer,Integer>>().set(1,statistics); |
| | | } |
| | | |
| | | public Response<PageInfo<WorkflowMain>> ownListPage(int userId, int type, int status, int pageNum, int pageSize) { |
| | | PageHelper.startPage(pageNum,pageSize); |
| | | List<WorkflowMain> mains = getOwnListByUserAndType(userId,type,status); |
| | | if(type == 1) { |
| | | for (WorkflowMain main : mains) { |
| | | Integer id = main.getId(); |
| | | List<BattDischargePlanTemp> tempList = tempService.getListByMainId(id); |
| | | main.setTempList(tempList); |
| | | } |
| | | } |
| | | PageInfo<WorkflowMain> pageInfo = new PageInfo<>(mains); |
| | | return new Response<PageInfo<WorkflowMain>>().set(1,pageInfo); |
| | | } |
| | | |
| | | private List<WorkflowMain> getOwnListByUserAndType(int userId, int type, int status) { |
| | | QueryWrapper<WorkflowMain> query = Wrappers.query(); |
| | | if(status == 0){ |
| | | query.eq("create_user_id",userId).eq("type",type); |
| | | }else { |
| | | query.eq("create_user_id", userId).eq("type", type).eq("status", status); |
| | | } |
| | | return mapper.selectList(query); |
| | | } |
| | | |
| | | public Response<Map<Integer,Integer>> getReceivedStatistics(int type, UserInf user) { |
| | | Map<Integer,Integer> statisticsMap = linkService.getReceivedStatistics(type,user); |
| | | return new Response<Map<Integer,Integer>>().set(1,statisticsMap); |
| | | } |
| | | |
| | | public Response<PageInfo<WorkflowMain>> getReceivedListPage(int type, int status, UserInf user, int pageNum, int pageSize) { |
| | | PageHelper.startPage(pageNum,pageSize); |
| | | List<WorkflowMain> mains = getReceivedListByUserAndType(user,type,status); |
| | | if (type == 1) { |
| | | for (WorkflowMain main : mains) { |
| | | Integer id = main.getId(); |
| | | List<BattDischargePlanTemp> tempList = tempService.getListByMainId(id); |
| | | main.setTempList(tempList); |
| | | } |
| | | } |
| | | PageInfo<WorkflowMain> pageInfo = new PageInfo<>(mains); |
| | | return new Response<PageInfo<WorkflowMain>>().set(1, pageInfo); |
| | | } |
| | | |
| | | private List<WorkflowMain> getReceivedListByUserAndType(UserInf user, int type, int status) { |
| | | return mapper.getReceivedListByUserAndType(user, type, status); |
| | | } |
| | | |
| | | public WorkflowMain getOne(Integer mainId) { |
| | | return mapper.selectById(mainId); |
| | | } |
| | | |
| | | //查询表单编号 |
| | | public int getMaxId() { |
| | | Integer id = mapper.getMaxId(); |
| | | if (id == null) { |
| | | id = 1; |
| | | } else { |
| | | id = id + 1; |
| | | } |
| | | return id; |
| | | } |
| | | |
| | | //插入主表带指定主键id不要自增 |
| | | public void addWorkMain(WorkflowMain main) { |
| | | mapper.addWorkMain(main); |
| | | } |
| | | |
| | | } |