|
@@ -1,15 +1,19 @@
|
|
|
package com.management.platform.controller;
|
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.management.platform.entity.*;
|
|
|
-import com.management.platform.service.PlanService;
|
|
|
-import com.management.platform.service.PlanSteelStampNumberService;
|
|
|
-import com.management.platform.service.ReportService;
|
|
|
+import com.management.platform.mapper.UserMapper;
|
|
|
+import com.management.platform.service.*;
|
|
|
+import com.management.platform.util.DateTimeUtil;
|
|
|
import com.management.platform.util.HttpRespMsg;
|
|
|
import org.apache.ibatis.annotations.Param;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
@@ -19,7 +23,14 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Optional;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -39,6 +50,18 @@ public class PlanController {
|
|
|
private PlanSteelStampNumberService planSteelStampNumberService;
|
|
|
@Resource
|
|
|
private ReportService reportService;
|
|
|
+ @Resource
|
|
|
+ private PlanExtraInfoService extraInfoService;
|
|
|
+ @Resource
|
|
|
+ WxCorpTemplateService wxCorpTemplateService;
|
|
|
+ @Resource
|
|
|
+ private WxCorpInfoService wxCorpInfoService;
|
|
|
+ @Resource
|
|
|
+ TaskTypeService taskTypeService;
|
|
|
+ @Resource
|
|
|
+ UserMapper userMapper;
|
|
|
+ @Resource
|
|
|
+ DepartmentService departmentService;
|
|
|
|
|
|
@RequestMapping("/list")
|
|
|
public HttpRespMsg list(String date,String steelStampNumber,@RequestParam(defaultValue = "3") Integer planType,Integer deptId,Integer pageIndex,Integer pageSize,Integer isMob,Integer searchType,String searchValue){
|
|
@@ -219,5 +242,337 @@ public class PlanController {
|
|
|
public HttpRespMsg updateHasDeleteTeamData(){
|
|
|
return reportService.updateHasDeleteTeamData();
|
|
|
}
|
|
|
+
|
|
|
+ @RequestMapping("/getTemporaryJobApplicationNew")
|
|
|
+ public HttpRespMsg getTemporaryJobApplicationNew(String startDate, String endDate) throws Exception {
|
|
|
+ HttpRespMsg httpRespMsg=new HttpRespMsg();
|
|
|
+ JSONArray jsonArrayFilter = new JSONArray();
|
|
|
+ JSONObject filter1 = new JSONObject();
|
|
|
+ WxCorpTemplate template = wxCorpTemplateService.getOne(new QueryWrapper<WxCorpTemplate>().eq("company_id",7).eq("type",2));//类型设置为2
|
|
|
+ filter1.put("key","template_id");
|
|
|
+ filter1.put("value",template.getTemplateId());
|
|
|
+ jsonArrayFilter.add(filter1);
|
|
|
+ JSONObject filter2 = new JSONObject();
|
|
|
+ filter2.put("key","sp_status");
|
|
|
+ filter2.put("value","2");
|
|
|
+ jsonArrayFilter.add(filter2);
|
|
|
+ System.out.println("开始获取getTemporaryJobApplicationNew==计件工单数据==!!");
|
|
|
+ List<String> approvalInfo = wxCorpInfoService.getApprovalInfo(7, startDate, endDate, "", jsonArrayFilter);
|
|
|
+ List<Department> departmentList = departmentService.list(new LambdaQueryWrapper<Department>().eq(Department::getCompanyId, 7));
|
|
|
+ List<TaskType> taskTypeList = taskTypeService.list(new LambdaQueryWrapper<TaskType>().eq(TaskType::getCompanyId, 7));
|
|
|
+ List<User> userList = userMapper.selectList(new LambdaQueryWrapper<User>().eq(User::getCompanyId,7));
|
|
|
+ if(approvalInfo!=null){
|
|
|
+ System.out.println("计件工单数据="+approvalInfo.size()+"条");
|
|
|
+ for (int i = 0; i < approvalInfo.size(); i++) {
|
|
|
+ String codeNum = approvalInfo.get(i);
|
|
|
+ String approvalInfoDetailResp = wxCorpInfoService.getApprovalInfoDetail(7, codeNum);
|
|
|
+ JSONObject approvalInfoDetail = JSONObject.parseObject(approvalInfoDetailResp);
|
|
|
+ JSONObject info = approvalInfoDetail.getJSONObject("info");
|
|
|
+ JSONObject applyer = info.getJSONObject("applyer");
|
|
|
+ String userid = applyer.getString("userid");
|
|
|
+ //过滤审核状态只需要审核通过的数据
|
|
|
+ int sp_status = info.getIntValue("sp_status");
|
|
|
+ if(sp_status!=2){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Optional<User> first = userList.stream().filter(u ->u.getCorpwxRealUserid()!=null&&u.getCorpwxRealUserid().equals(userid)).findFirst();
|
|
|
+ if(!first.isPresent()){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JSONObject apply_data = info.getJSONObject("apply_data");
|
|
|
+ System.out.println("获取到的单据信息===========>"+apply_data);
|
|
|
+ JSONArray contents = apply_data.getJSONArray("contents");
|
|
|
+ //生成 车间插单计划
|
|
|
+ List<Plan> planList = planService.list(new LambdaQueryWrapper<Plan>().eq(Plan::getTaskChangeNoticeNum, info.getString("sp_no")));
|
|
|
+ Plan plan=new Plan();
|
|
|
+ if(!planList.isEmpty()){
|
|
|
+ plan.setId(planList.get(0).getId());
|
|
|
+ }
|
|
|
+ plan.setCompanyId(7);
|
|
|
+ plan.setCreateTime(LocalDateTime.now());
|
|
|
+ plan.setPlanType(1);
|
|
|
+ plan.setCreateId(first.get().getId());
|
|
|
+ plan.setTaskChangeNoticeNum(info.getString("sp_no"));
|
|
|
+ //参与人员列表
|
|
|
+ List<String> userTeams=new ArrayList<>();
|
|
|
+ //初始化 单价(元/小时)
|
|
|
+ BigDecimal price=new BigDecimal(0);
|
|
|
+ //初始化 工作时长
|
|
|
+ double workTime=0;
|
|
|
+
|
|
|
+ long apply_time = info.getLongValue("apply_time");
|
|
|
+ LocalDate createDate;
|
|
|
+ if(apply_time>0){
|
|
|
+ createDate= DateTimeUtil.getLocalDateFromUnix(apply_time);
|
|
|
+ }else {
|
|
|
+ createDate =LocalDate.now();
|
|
|
+ }
|
|
|
+ //初始化工位
|
|
|
+ Integer deptId=0;
|
|
|
+ long startTime=0;
|
|
|
+ long endTime=0;
|
|
|
+ String steelNumArray="";
|
|
|
+ String operationName="";
|
|
|
+ String partName="";
|
|
|
+ for (int i1 = 0; i1 < contents.size(); i1++) {
|
|
|
+ JSONObject map = contents.getJSONObject(i1);
|
|
|
+ JSONArray title = map.getJSONArray("title");
|
|
|
+ JSONObject value = map.getJSONObject("value");
|
|
|
+ String control = map.getString("control");
|
|
|
+ /*if(title.getJSONObject(0).getString("text").equals("临时报工分类")){
|
|
|
+ if(control.equals("Selector")){
|
|
|
+ JSONObject selector = value.getJSONObject("selector");
|
|
|
+ JSONArray options = selector.getJSONArray("options");
|
|
|
+ JSONObject object = options.getJSONObject(0);
|
|
|
+ JSONArray value1 = object.getJSONArray("value");
|
|
|
+ JSONObject jsonObject = value1.getJSONObject(0);
|
|
|
+ String text = jsonObject.getString("text");
|
|
|
+ Optional<TaskType> first1 = taskTypeList.stream().filter(t -> t.getTaskTypeName().equals(text)).findFirst();
|
|
|
+ if(first1.isPresent()){
|
|
|
+ plan.setTaskTypeId(first1.get().getId());
|
|
|
+ plan.setTaskTypeName(first1.get().getTaskTypeName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }*/
|
|
|
+ if(title.getJSONObject(0).getString("text").equals("项目名称")){
|
|
|
+ if(control.equals("Text")||control.equals("Textarea")){
|
|
|
+ String text = value.getString("text");
|
|
|
+ plan.setProjectName(text);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(title.getJSONObject(0).getString("text").contains("包名称")){
|
|
|
+ if(control.equals("Text")||control.equals("Textarea")){
|
|
|
+ String text = value.getString("text");
|
|
|
+ plan.setProductSchedulingNum(text);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(title.getJSONObject(0).getString("text").equals("生产订单号")){
|
|
|
+ if(control.equals("Text")||control.equals("Textarea")){
|
|
|
+ String text = value.getString("text");
|
|
|
+ plan.setProductOrderNum(text);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(title.getJSONObject(0).getString("text").equals("工序名称")){
|
|
|
+ if(control.equals("Text")||control.equals("Textarea")){
|
|
|
+ String text = value.getString("text");
|
|
|
+ operationName=text;//工序名称
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(title.getJSONObject(0).getString("text").equals("零件编码")){
|
|
|
+ if(control.equals("Text")||control.equals("Textarea")){
|
|
|
+ String text = value.getString("text");
|
|
|
+ steelNumArray=text;//零件编码
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(title.getJSONObject(0).getString("text").equals("零件名称")){
|
|
|
+ if(control.equals("Text")||control.equals("Textarea")){
|
|
|
+ String text = value.getString("text");
|
|
|
+ partName=text;//零件名称
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(title.getJSONObject(0).getString("text").equals("生产数量")){
|
|
|
+ if(control.equals("Number")){
|
|
|
+ int new_number= value.get("new_number")!=null?value.getIntValue("new_number"):0;
|
|
|
+ plan.setNum(new_number);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(title.getJSONObject(0).getString("text").equals("作业单位")){
|
|
|
+ if(control.equals("Contact")){
|
|
|
+ JSONArray departments = value.getJSONArray("departments");
|
|
|
+ String openapi_id = departments.getJSONObject(0).getString("openapi_id");
|
|
|
+ Optional<Department> first1 = departmentList.stream().filter(d -> d.getCorpwxDeptid().equals(Integer.valueOf(openapi_id))).findFirst();
|
|
|
+ if(first1.isPresent()){
|
|
|
+ plan.setStationId(first1.get().getDepartmentId());
|
|
|
+ plan.setStationName(first1.get().getDepartmentName());
|
|
|
+ plan.setForemanId(first1.get().getManagerId());
|
|
|
+ Optional<User> first2 = userList.stream().filter(u -> u.getId().equals(first1.get().getManagerId())).findFirst();
|
|
|
+ if(first2.isPresent()){
|
|
|
+ plan.setForemanName(first2.get().getName());
|
|
|
+ }
|
|
|
+ deptId=first1.get().getDepartmentId();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(title.getJSONObject(0).getString("text").contains("单价")){
|
|
|
+ if(control.equals("Number")){
|
|
|
+ if(!value.getString("new_number").equals("")){
|
|
|
+ Double new_money = value.getDouble("new_number");
|
|
|
+ plan.setMoneyOfJob(new BigDecimal(new_money==null?0:new_money));
|
|
|
+ price=new BigDecimal(new_money);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(title.getJSONObject(0).getString("text").contains("结算总额")){
|
|
|
+ if(control.equals("Formula")){
|
|
|
+ JSONObject formula = value.getJSONObject("formula");
|
|
|
+ if(!formula.getString("value").equals("")){
|
|
|
+ double formulaDoubleValue = formula.getDoubleValue("value");
|
|
|
+ BigDecimal bigDecimal = new BigDecimal(formulaDoubleValue);
|
|
|
+ if(workTime>0){
|
|
|
+ BigDecimal divide = bigDecimal.divide(new BigDecimal(workTime), 3, RoundingMode.HALF_UP);
|
|
|
+ plan.setMoneyOfJob(divide);
|
|
|
+ }
|
|
|
+ plan.setSettlementAmount(bigDecimal);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //先处理多个人员 公用此单据非工时部分内容
|
|
|
+ if(title.getJSONObject(0).getString("text").equals("作业人员")){
|
|
|
+ if(control.equals("Contact")){
|
|
|
+ JSONArray members = value.getJSONArray("members");
|
|
|
+ plan.setPlanManNum(members.size());
|
|
|
+ for (int i2 = 0; i2 < members.size(); i2++) {
|
|
|
+ JSONObject jsonObject = members.getJSONObject(i2);
|
|
|
+ String userid1 = jsonObject.getString("userid");
|
|
|
+ userTeams.add(userid1);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if(title.getJSONObject(0).getString("text").equals("作业开始日期")){
|
|
|
+ if(control.equals("Date")){
|
|
|
+ JSONObject date = value.getJSONObject("date");
|
|
|
+ long s_timestamp = date.getLongValue("s_timestamp");
|
|
|
+ startTime=s_timestamp;
|
|
|
+ LocalDate localDateFromUnix = DateTimeUtil.getLocalDateFromUnix(s_timestamp);
|
|
|
+ plan.setStartDate(localDateFromUnix);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(title.getJSONObject(0).getString("text").equals("作业结束日期")){
|
|
|
+ if(control.equals("Date")){
|
|
|
+ long s_timestamp=0;
|
|
|
+ JSONObject date = value.getJSONObject("date");
|
|
|
+ if (!StringUtils.isEmpty(date.getString("s_timestamp"))){
|
|
|
+ s_timestamp= date.getLongValue("s_timestamp");
|
|
|
+ LocalDate localDateFromUnix = DateTimeUtil.getLocalDateFromUnix(s_timestamp);
|
|
|
+ plan.setEndDate(localDateFromUnix);
|
|
|
+ }
|
|
|
+ if (s_timestamp!=0){
|
|
|
+ endTime=s_timestamp;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (endTime>0){
|
|
|
+ long l = endTime - startTime;//工作时长
|
|
|
+ workTime=l/3600.0;
|
|
|
+ plan.setPlanWorkHour(workTime);//小时
|
|
|
+
|
|
|
+ startTime=0;
|
|
|
+ endTime=0;
|
|
|
+ }
|
|
|
+ if(title.getJSONObject(0).getString("text").equals("所属工位长")){
|
|
|
+ if(control.equals("Contact")){
|
|
|
+ JSONArray members = value.getJSONArray("members");
|
|
|
+ String userid2 = members.getJSONObject(0).getString("userid");
|
|
|
+ User user = userMapper.selectOne(new QueryWrapper<User>().eq("corpwx_real_userid", userid2));
|
|
|
+ Department department = departmentService.getById(user.getDepartmentId());
|
|
|
+ if (user != null) {
|
|
|
+ plan.setForemanId(user.getId());
|
|
|
+ plan.setForemanName(user.getName());
|
|
|
+ if (department != null) {
|
|
|
+ plan.setStationId(department.getDepartmentId());
|
|
|
+ plan.setStationName(department.getDepartmentName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(title.getJSONObject(0).getString("text").equals("备注")){
|
|
|
+ if(control.equals("Text")||control.equals("Textarea")){
|
|
|
+ String text = value.getString("text");
|
|
|
+ plan.setDescribtion(text);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (plan.getId()!=null){
|
|
|
+ planService.update(new UpdateWrapper<Plan>().eq("id", plan.getId()).set("money_of_job",plan.getMoneyOfJob()));
|
|
|
+ int count = reportService.count(new QueryWrapper<Report>().eq("plan_id", plan.getId()));
|
|
|
+ if (count!=userTeams.size()){
|
|
|
+// log.info("userTeams的长度:"+userTeams.size());
|
|
|
+// log.info("userTeams的内容:"+(userTeams.isEmpty() ?"":userTeams.toString()));
|
|
|
+// log.info("plan.getSettlementAmount():"+plan.getSettlementAmount());
|
|
|
+ reportService.remove(new QueryWrapper<Report>().eq("plan_id", plan.getId()));
|
|
|
+ List<Report> reportList = new ArrayList<>();
|
|
|
+ List<PlanExtraInfo> planExtraInfoList = new ArrayList<>();
|
|
|
+
|
|
|
+ //处理人员日报数据
|
|
|
+ for (String userTeam : userTeams) {
|
|
|
+ Optional<User> user = userList.stream().filter(u -> u.getCorpwxRealUserid() != null && u.getCorpwxRealUserid().equals(userTeam)).findFirst();
|
|
|
+ if (user.isPresent()) {
|
|
|
+ Report report = new Report();
|
|
|
+ report.setCreateDate(createDate);
|
|
|
+ report.setCreatorId(user.get().getId());
|
|
|
+ report.setCreateTime(LocalDateTime.now());
|
|
|
+ BigDecimal bigDecimal = new BigDecimal(workTime);
|
|
|
+ report.setWorkingTime(bigDecimal.doubleValue());
|
|
|
+ report.setCost(plan.getSettlementAmount().divide(BigDecimal.valueOf(userTeams.size()), 2, RoundingMode.HALF_UP));
|
|
|
+ report.setStatus(2);
|
|
|
+ report.setPlanId(plan.getId());
|
|
|
+ report.setCompanyId(7);
|
|
|
+ report.setDeptId(user.get().getDepartmentId());
|
|
|
+ report.setSteelNumArray(steelNumArray);
|
|
|
+ reportList.add(report);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (reportList.size() > 0) {
|
|
|
+ reportService.saveBatch(reportList);
|
|
|
+ for (Report report : reportList) {
|
|
|
+ PlanExtraInfo planExtraInfo = new PlanExtraInfo();
|
|
|
+ planExtraInfo.setPlanId(plan.getId());
|
|
|
+ planExtraInfo.setReportId(report.getId());
|
|
|
+ planExtraInfo.setOperationName(operationName);
|
|
|
+ planExtraInfo.setPartName(partName);
|
|
|
+ planExtraInfoList.add(planExtraInfo);
|
|
|
+ }
|
|
|
+ if (planExtraInfoList.size() > 0) {
|
|
|
+ extraInfoService.saveBatch(planExtraInfoList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ planService.save(plan);
|
|
|
+ List<Report> reportList = new ArrayList<>();
|
|
|
+ List<PlanExtraInfo> planExtraInfoList = new ArrayList<>();
|
|
|
+
|
|
|
+ //处理人员日报数据
|
|
|
+ for (String userTeam : userTeams) {
|
|
|
+ Optional<User> user = userList.stream().filter(u -> u.getCorpwxRealUserid() != null && u.getCorpwxRealUserid().equals(userTeam)).findFirst();
|
|
|
+ if (user.isPresent()) {
|
|
|
+ Report report = new Report();
|
|
|
+ report.setCreateDate(createDate);
|
|
|
+ report.setCreatorId(user.get().getId());
|
|
|
+ report.setCreateTime(LocalDateTime.now());
|
|
|
+ BigDecimal bigDecimal = new BigDecimal(workTime);
|
|
|
+ report.setWorkingTime(bigDecimal.doubleValue());
|
|
|
+ report.setCost(plan.getSettlementAmount().divide(BigDecimal.valueOf(userTeams.size()), 2, RoundingMode.HALF_UP));
|
|
|
+ report.setStatus(2);
|
|
|
+ report.setPlanId(plan.getId());
|
|
|
+ report.setCompanyId(7);
|
|
|
+ report.setDeptId(user.get().getDepartmentId());
|
|
|
+ report.setSteelNumArray(steelNumArray);
|
|
|
+ reportList.add(report);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (reportList.size() > 0) {
|
|
|
+ reportService.saveBatch(reportList);
|
|
|
+ for (Report report : reportList) {
|
|
|
+ PlanExtraInfo planExtraInfo = new PlanExtraInfo();
|
|
|
+ planExtraInfo.setPlanId(plan.getId());
|
|
|
+ planExtraInfo.setReportId(report.getId());
|
|
|
+ planExtraInfo.setOperationName(operationName);
|
|
|
+ planExtraInfo.setPartName(partName);
|
|
|
+ planExtraInfoList.add(planExtraInfo);
|
|
|
+ }
|
|
|
+ if (planExtraInfoList.size() > 0) {
|
|
|
+ extraInfoService.saveBatch(planExtraInfoList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
}
|
|
|
|