package com.zcloud.controller.bus; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.zcloud.aspect.DockAnnotation; import com.zcloud.controller.base.BaseController; import com.zcloud.entity.Page; import com.zcloud.entity.PageData; import com.zcloud.service.bus.ShiftWorkPeriodService; import com.zcloud.service.bus.ShiftWorkRulesService; import com.zcloud.service.system.UsersService; import com.zcloud.util.DateUtil; import com.zcloud.util.Jurisdiction; import com.zcloud.util.ObjectExcelView; import com.zcloud.util.Tools; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; import java.util.*; /** * 说明:倒班规则 * 作者:luoxiaobao * 时间:2021-12-07 * 官网:www.zcloudchina.com */ @Controller @RequestMapping("/shiftworkrules") public class ShiftWorkRulesController extends BaseController { @Autowired private ShiftWorkRulesService shiftworkrulesService; @Autowired private ShiftWorkPeriodService shiftWorkPeriodService; @Autowired private UsersService usersService; /**新增 * @param * @throws Exception */ @RequestMapping(value="/add") @RequiresPermissions("shiftworkrules:add") @ResponseBody @DockAnnotation public Object add() throws Exception{ Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); pd.put("SHIFTWORKRULES_ID", this.get32UUID()); //主键 pd.put("CREATOR", Jurisdiction.getUSER_ID()); //添加人 pd.put("CREATTIME", DateUtil.date2Str(new Date())); //添加时间 pd.put("OPERATOR", Jurisdiction.getUSER_ID()); //修改人 pd.put("OPERATTIME", DateUtil.date2Str(new Date())); //修改时间 pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); // 企业id pd.put("ISDELETE", "0"); //是否删除 1-是 0-否 if (Tools.notEmpty(pd.getString("ISCUSTOM")) && "1".equals(pd.getString("ISCUSTOM")) && pd.get("periodList") != null && !pd.get("periodList").equals("")) { List periodList = (List) JSON.parse(pd.get("periodList").toString()); ArrayList periodLists = new ArrayList<>(); for (int i = 0; i < periodList.size(); i++) { PageData period = new PageData(); period.put("SHIFTWORKPERIOD_ID",this.get32UUID()); period.put("ONDAY",periodList.get(i).get("ONDAY")); period.put("OFFDAY",periodList.get(i).get("OFFDAY")); period.put("CREATOR", Jurisdiction.getUSER_ID()); //添加人 period.put("CREATTIME", DateUtil.date2Str(new Date())); //添加时间 period.put("OPERATOR", Jurisdiction.getUSER_ID()); //修改人 period.put("OPERATTIME", DateUtil.date2Str(new Date())); //修改时间 period.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); // 企业id period.put("ISDELETE", "0"); //是否删除 1-是 0-否 period.put("SHIFTWORKRULES_ID", pd.get("SHIFTWORKRULES_ID")); period.put("SORT", i+1); period.put("ISEND", i < periodList.size()-1 ? 0 : 1); periodLists.add(period); shiftWorkPeriodService.save(period); } pd.put("periodList",JSON.toJSONString(periodLists)); } shiftworkrulesService.save(pd); map.put("result", errInfo); map.put("dockData",JSON.toJSONString(pd)); return map; } /**删除 * @param out * @throws Exception */ @RequestMapping(value="/deleteOne") @RequiresPermissions("shiftworkrules:del") @ResponseBody public Object deleteOne() throws Exception{ Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); pd.put("SHIFTDUTYONE", pd.get("SHIFTWORKRULES_ID")); int count = shiftworkrulesService.isUseOne(pd); if(count == 0) { pd.put("OPERATOR", Jurisdiction.getUSER_ID()); //修改人 pd.put("OPERATTIME", DateUtil.date2Str(new Date())); //修改时间 shiftWorkPeriodService.deleteByUpRules(pd); shiftworkrulesService.delete(pd); pd.put("PARENTID", pd.get("SHIFTWORKRULES_ID")); shiftworkrulesService.deleteByPar(pd); map.put("type", "success"); //返回结果 } else { map.put("type", "error"); //返回结果 } map.put("result", errInfo); //返回结果 return map; } /**删除 * @param out * @throws Exception */ @RequestMapping(value="/deleteTwo") @RequiresPermissions("shiftworkrules:del") @ResponseBody public Object deleteTwo() throws Exception{ Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); pd.put("SHIFTDUTYTWO", pd.get("SHIFTWORKRULES_ID")); int count = shiftworkrulesService.isUseTwo(pd); if(count == 0) { pd.put("OPERATOR", Jurisdiction.getUSER_ID()); //修改人 pd.put("OPERATTIME", DateUtil.date2Str(new Date())); //修改时间 shiftWorkPeriodService.deleteByRules(pd); shiftworkrulesService.delete(pd); map.put("type", "success"); //返回结果 } else { map.put("type", "error"); //返回结果 } map.put("result", errInfo); //返回结果 return map; } /**验证排班周期是否使用中 * @param out * @throws Exception */ @RequestMapping(value="/isUseTwo") @ResponseBody public Object isUseTwo() throws Exception{ Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); pd.put("SHIFTDUTYTWO", pd.get("SHIFTWORKRULES_ID")); int count = shiftworkrulesService.isUseTwo(pd); if(count == 0) { map.put("type", "success"); //返回结果 } else { map.put("type", "error"); //返回结果 } map.put("result", errInfo); //返回结果 return map; } /**修改 * @param * @throws Exception */ @RequestMapping(value="/edit") @RequiresPermissions("shiftworkrules:edit") @ResponseBody public Object edit() throws Exception{ Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); pd.put("OPERATOR", Jurisdiction.getUSER_ID()); //修改人 pd.put("OPERATTIME", DateUtil.date2Str(new Date())); //修改时间 shiftworkrulesService.edit(pd); if (Tools.notEmpty(pd.getString("ISCUSTOM")) && "1".equals(pd.getString("ISCUSTOM")) && pd.get("periodList") != null && !pd.get("periodList").equals("")) { List periodList = (List) JSON.parse(pd.get("periodList").toString()); shiftWorkPeriodService.deleteByRules(pd); for (int i = 0; i < periodList.size(); i++) { PageData period = new PageData(); period.put("SHIFTWORKPERIOD_ID",this.get32UUID()); period.put("ONDAY",periodList.get(i).get("ONDAY")); period.put("OFFDAY",periodList.get(i).get("OFFDAY")); period.put("CREATOR", Jurisdiction.getUSER_ID()); //添加人 period.put("CREATTIME", DateUtil.date2Str(new Date())); //添加时间 period.put("OPERATOR", Jurisdiction.getUSER_ID()); //修改人 period.put("OPERATTIME", DateUtil.date2Str(new Date())); //修改时间 period.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); // 企业id period.put("ISDELETE", "0"); //是否删除 1-是 0-否 period.put("SHIFTWORKRULES_ID", pd.get("SHIFTWORKRULES_ID")); period.put("SORT", i+1); period.put("ISEND", i < periodList.size()-1 ? 0 : 1); shiftWorkPeriodService.save(period); } } map.put("result", errInfo); return map; } /**列表 * @param page * @throws Exception */ @RequestMapping(value="/list") @RequiresPermissions("shiftworkrules:list") @ResponseBody public Object list(Page page) throws Exception{ Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); // 企业id String KEYWORDS = pd.getString("KEYWORDS"); //关键词检索条件 if(Tools.notEmpty(KEYWORDS))pd.put("KEYWORDS", KEYWORDS.trim()); page.setPd(pd); List varList = shiftworkrulesService.list(page); //列出ShiftWorkRules列表 map.put("varList", varList); map.put("page", page); map.put("result", errInfo); return map; } /**去修改页面获取数据 * @param * @throws Exception */ @RequestMapping(value="/goEdit") @RequiresPermissions("shiftworkrules:edit") @ResponseBody public Object goEdit() throws Exception{ Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); pd = shiftworkrulesService.findById(pd); //根据ID读取 List periodList = shiftWorkPeriodService.listAll(pd); map.put("pd", pd); map.put("periodList", periodList); map.put("result", errInfo); return map; } /**获取倒班规则集合 * @param * @throws Exception */ @RequestMapping(value="/listAll") @ResponseBody public Object listAll() throws Exception{ Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); // 企业 List varList = shiftworkrulesService.listAll(pd); //根据ID读取 pd = usersService.findById(pd); //根据ID读取 map.put("varList", varList); map.put("pd",pd); map.put("result", errInfo); return map; } /**批量删除 * @param * @throws Exception */ @RequestMapping(value="/deleteAll") @RequiresPermissions("shiftworkrules:del") @ResponseBody public Object deleteAll() throws Exception{ Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); String DATA_IDS = pd.getString("DATA_IDS"); if(Tools.notEmpty(DATA_IDS)){ String ArrayDATA_IDS[] = DATA_IDS.split(","); shiftworkrulesService.deleteAll(ArrayDATA_IDS); errInfo = "success"; }else{ errInfo = "fail"; } map.put("result", errInfo); //返回结果 return map; } /**导出到excel * @param * @throws Exception */ @RequestMapping(value="/excel") // @RequiresPermissions("toExcel") public ModelAndView exportExcel() throws Exception{ ModelAndView mv = new ModelAndView(); PageData pd = new PageData(); pd = this.getPageData(); Map dataMap = new HashMap(); List titles = new ArrayList(); titles.add("倒班规则数据字典编码"); //1 titles.add("连续上班天数(周期一)"); //2 titles.add("连续休班天数(周期一)"); //3 titles.add("连续上班天数(周期二)"); //4 titles.add("连续休班天数(周期二)"); //5 titles.add("连续上班天数(周期三)"); //6 titles.add("连续休班天数(周期三)"); //7 titles.add("企业ID"); //8 titles.add("添加人"); //9 titles.add("添加时间"); //10 titles.add("修改人"); //11 titles.add("修改时间"); //12 titles.add("是否删除 1-是 0-否"); //13 dataMap.put("titles", titles); List varOList = shiftworkrulesService.listAll(pd); List varList = new ArrayList(); for(int i=0;i