| | |
| | | */ |
| | | package com.java110.store.cmd.scheduleClasses; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.core.annotation.Java110Cmd; |
| | | import com.java110.core.annotation.Java110Transactional; |
| | |
| | | import com.java110.core.event.cmd.Cmd; |
| | | import com.java110.core.event.cmd.CmdEvent; |
| | | import com.java110.core.factory.GenerateCodeFactory; |
| | | import com.java110.dto.scheduleClassesStaff.ScheduleClassesStaffDto; |
| | | import com.java110.intf.store.IScheduleClassesStaffV1InnerServiceSMO; |
| | | import com.java110.po.inspection.InspectionPlanStaffPo; |
| | | import com.java110.po.scheduleClassesStaff.ScheduleClassesStaffPo; |
| | | import com.java110.utils.exception.CmdException; |
| | | import com.java110.utils.util.Assert; |
| | |
| | | @Override |
| | | public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) { |
| | | Assert.hasKeyAndValue(reqJson, "scheduleId", "请求报文中未包含scheduleId"); |
| | | Assert.hasKeyAndValue(reqJson, "storeId", "请求报文中未包含storeId"); |
| | | Assert.hasKeyAndValue(reqJson, "staffId", "请求报文中未包含staffId"); |
| | | Assert.hasKeyAndValue(reqJson, "staffName", "请求报文中未包含staffName"); |
| | | |
| | | if(!reqJson.containsKey("staffs")){ |
| | | throw new CmdException("未包含员工"); |
| | | } |
| | | |
| | | JSONArray staffs = reqJson.getJSONArray("staffs"); |
| | | if(staffs.size() < 1){ |
| | | throw new CmdException("未包含员工"); |
| | | } |
| | | long count = 0; |
| | | ScheduleClassesStaffDto scheduleClassesStaffDto = null; |
| | | for(int staffIndex = 0; staffIndex < staffs.size() ; staffIndex++) { |
| | | scheduleClassesStaffDto = new ScheduleClassesStaffDto(); |
| | | //scheduleClassesStaffDto.setScheduleId(reqJson.getString("scheduleId")); |
| | | scheduleClassesStaffDto.setStaffId(staffs.getJSONObject(staffIndex).getString("userId")); |
| | | count = scheduleClassesStaffV1InnerServiceSMOImpl.queryScheduleClassesStaffsCount(scheduleClassesStaffDto); |
| | | |
| | | if(count > 0){ |
| | | throw new CmdException(staffs.getJSONObject(staffIndex).getString("name")+"员工已经存在排班"); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | |
| | | @Java110Transactional |
| | | public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException { |
| | | |
| | | ScheduleClassesStaffPo scheduleClassesStaffPo = BeanConvertUtil.covertBean(reqJson, ScheduleClassesStaffPo.class); |
| | | scheduleClassesStaffPo.setScsId(GenerateCodeFactory.getGeneratorId(CODE_PREFIX_ID)); |
| | | int flag = scheduleClassesStaffV1InnerServiceSMOImpl.saveScheduleClassesStaff(scheduleClassesStaffPo); |
| | | String storeId = cmdDataFlowContext.getReqHeaders().get("store-id"); |
| | | JSONArray staffs = reqJson.getJSONArray("staffs"); |
| | | ScheduleClassesStaffPo scheduleClassesStaffPo = null; |
| | | |
| | | if (flag < 1) { |
| | | throw new CmdException("保存数据失败"); |
| | | int flag = 0; |
| | | for(int staffIndex = 0; staffIndex < staffs.size() ; staffIndex++) { |
| | | scheduleClassesStaffPo = new ScheduleClassesStaffPo(); |
| | | scheduleClassesStaffPo.setStoreId(storeId); |
| | | scheduleClassesStaffPo.setScheduleId(reqJson.getString("scheduleId")); |
| | | scheduleClassesStaffPo.setScsId(GenerateCodeFactory.getGeneratorId(CODE_PREFIX_ID)); |
| | | scheduleClassesStaffPo.setStaffId(staffs.getJSONObject(staffIndex).getString("userId")); |
| | | scheduleClassesStaffPo.setStaffName(staffs.getJSONObject(staffIndex).getString("name")); |
| | | scheduleClassesStaffPo.setStoreId(storeId); |
| | | flag = scheduleClassesStaffV1InnerServiceSMOImpl.saveScheduleClassesStaff(scheduleClassesStaffPo); |
| | | if (flag < 1) { |
| | | throw new CmdException("保存数据失败"); |
| | | } |
| | | |
| | | } |
| | | |
| | | cmdDataFlowContext.setResponseEntity(ResultVo.success()); |