package com.ld.igds.m.view;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.bstek.bdf2.core.model.DefaultDept;
|
import com.bstek.dorado.annotation.DataProvider;
|
import com.bstek.dorado.annotation.DataResolver;
|
import com.bstek.dorado.annotation.Expose;
|
import com.bstek.dorado.data.provider.Page;
|
import com.ld.igds.constant.Constant;
|
import com.ld.igds.constant.OrderStatus;
|
import com.ld.igds.constant.RespCodeEnum;
|
import com.ld.igds.m.dto.AppointParam;
|
import com.ld.igds.m.service.HAppointService;
|
import com.ld.igds.m.service.HInoutCustomerService;
|
import com.ld.igds.models.DicTrigger;
|
import com.ld.igds.models.InoutAppoint;
|
import com.ld.igds.models.InoutCustomer;
|
import com.ld.igds.sys.service.SysDeptService;
|
import com.ld.igds.util.ContextUtil;
|
import com.ld.igds.util.DateUtil;
|
import com.ld.igds.warn.data.MsgResponse;
|
import com.ld.igds.wechat.WeChatUtils;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import java.util.*;
|
|
/**
|
* 预约管理
|
*
|
* @author: czt
|
* @date 2023-04-12 17:45
|
*
|
*/
|
@Slf4j
|
@Component
|
public class AppointPR {
|
|
@Autowired
|
private SysDeptService sysDeptService;
|
@Autowired
|
private HInoutCustomerService customerService;
|
@Autowired
|
private HAppointService inoutAppointService;
|
@Autowired
|
private WeChatUtils weChatUtils;
|
|
|
/**
|
* 状态类型
|
* ${dorado.getDataProvider("appointPR#triggerStatusType").getResult()}
|
*
|
* @return
|
*/
|
@DataProvider
|
public List<DicTrigger> triggerStatusType() {
|
List<DicTrigger> list = new ArrayList<DicTrigger>();
|
|
list.add(new DicTrigger(OrderStatus.Status_10.getCode(), "待审核"));
|
list.add(new DicTrigger(OrderStatus.Status_20.getCode(), "通过"));
|
list.add(new DicTrigger(OrderStatus.Status_30.getCode(), "拒绝"));
|
list.add(new DicTrigger(OrderStatus.Status_40.getCode(), "退回"));
|
|
return list;
|
}
|
|
/**
|
* appointPR#pageInoutAppoint
|
* @param page
|
* @param param
|
* @throws Exception
|
*/
|
@DataProvider
|
public void pageInoutAppoint(Page<InoutAppoint> page, Map<String, Object> param) throws Exception {
|
if (null == param) {
|
param = new HashMap<String, Object>();
|
}
|
inoutAppointService.pageInoutAppoint(page, param);
|
}
|
|
|
/**
|
* 通过
|
* appointPR#auditPass
|
* @param data
|
* @return
|
*/
|
@Expose
|
public void auditPass(InoutAppoint data) {
|
data.setStatus(OrderStatus.Status_20.getCode());
|
data.setAuditTime(new Date());
|
data.setAuditUser(ContextUtil.getLoginUserCName());
|
inoutAppointService.saveOrUpInoutAppoint(data);
|
}
|
/**
|
* 拒绝
|
* appointPR#auditReject
|
* @param data
|
* @return
|
*/
|
@Expose
|
public void auditReject(InoutAppoint data) {
|
data.setStatus(OrderStatus.Status_30.getCode());
|
data.setAuditTime(new Date());
|
data.setAuditUser(ContextUtil.getLoginUserCName());
|
inoutAppointService.saveOrUpInoutAppoint(data);
|
}
|
|
/**
|
* 退回
|
* appointPR#auditBack
|
* @param data
|
* @return
|
*/
|
@Expose
|
public void auditBack(InoutAppoint data) {
|
data.setStatus(OrderStatus.Status_40.getCode());
|
data.setAuditTime(new Date());
|
data.setAuditUser(ContextUtil.getLoginUserCName());
|
inoutAppointService.saveOrUpInoutAppoint(data);
|
}
|
|
|
|
/**
|
* 同步出入库预约信息
|
*
|
* appointPR#syncInoutAppoint
|
*
|
* @return
|
*/
|
@Expose
|
public String syncInoutAppoint(AppointParam param) {
|
|
AppointParam appointParam = new AppointParam();
|
BeanUtils.copyProperties(param, appointParam);
|
|
if(StringUtils.isEmpty(appointParam.getDeptId())){
|
appointParam.setDeptId(ContextUtil.subDeptId(null));
|
}
|
if(StringUtils.isEmpty(appointParam.getCompanyId())){
|
appointParam.setCompanyId(ContextUtil.getCompanyId());
|
}
|
if(null == appointParam.getStartTime()){
|
appointParam.setStartTime(DateUtil.getCurZero(new Date()));
|
}
|
|
return syncInout(appointParam);
|
}
|
|
/**
|
* 推送出入库客户信息到公众号服务
|
*
|
* appointPR#pushCustomer
|
*
|
* @return
|
*/
|
@Expose
|
public String pushCustomer() {
|
|
//推送出入库客户信息到公众号服务
|
List<InoutCustomer> list = customerService.queryList(null);
|
|
if(null == list || list.isEmpty()){
|
log.warn("----------未获取到单位信息,不推送---------");
|
return "未获取到单位信息,不推送";
|
}
|
AppointParam param;
|
List<AppointParam> listData = new ArrayList<>();
|
for (InoutCustomer customer : list) {
|
param = new AppointParam();
|
param.setCustomerId(customer.getId());
|
param.setCustomerName(customer.getName());
|
param.setDeptId(customer.getDeptId());
|
param.setType(customer.getType());
|
listData.add(param);
|
}
|
MsgResponse response = weChatUtils.postToWeChat(listData, WeChatUtils.WECHAT_INTERFACEID_3002, ContextUtil.getCompanyId());
|
if(null == response || StringUtils.isEmpty(response.getCode()) || !RespCodeEnum.CODE_0000.getCode().equals(response.getCode())){
|
log.warn("----------单位{}信息推送失败,原因={}----------", listData, response);
|
return "单位信息推送失败";
|
}
|
log.info("----------单位信息推送成功={}----------", listData);
|
return "success";
|
}
|
|
/**
|
* 推送库区信息到公众号服务
|
*
|
* appointPR#pushDept
|
*
|
* @return
|
*/
|
@Expose
|
public String pushDept() {
|
|
List<DefaultDept> listDept = sysDeptService.getCacheDept(ContextUtil.getCompanyId());
|
if(null == listDept || listDept.isEmpty()){
|
return "未获取到库区信息,不推送!";
|
}
|
MsgResponse response;
|
AppointParam param;
|
List<AppointParam> listData = new ArrayList<>();
|
for (DefaultDept dept : listDept) {
|
if(Constant.DEPT_TYPE_20.equals(dept.getType())){
|
param = new AppointParam();
|
param.setDeptId(dept.getId());
|
param.setDeptName(dept.getName());
|
listData.add(param);
|
}
|
}
|
response = weChatUtils.postToWeChat(listData, WeChatUtils.WECHAT_INTERFACEID_3001, ContextUtil.getCompanyId());
|
if(null == response || StringUtils.isEmpty(response.getCode()) || !RespCodeEnum.CODE_0000.getCode().equals(response.getCode())){
|
log.warn("----------库区{}信息推送失败,原因={}----------", listData, response);
|
return "库区信息推送失败";
|
}
|
log.info("----------库区信息推送成功={}----------", listData);
|
return "success";
|
}
|
|
/**
|
* 同步出入库预约信息
|
* @param param
|
* @return
|
*/
|
public String syncInout(AppointParam param) {
|
|
MsgResponse response = weChatUtils.postToWeChat(param, WeChatUtils.WECHAT_INTERFACEID_3003, param.getCompanyId());
|
if(null == response || StringUtils.isEmpty(response.getCode()) || !RespCodeEnum.CODE_0000.getCode().equals(response.getCode())){
|
log.warn("----------出入库预约信息同步失败,原因={}----------", response);
|
return "同步失败";
|
}
|
List<InoutAppoint> list = JSONObject.parseArray(JSONObject.toJSONString(response.getData()), InoutAppoint.class);
|
if(null == list || list.isEmpty()){
|
log.warn("----------同步出入库信息为空,不处理----------");
|
return "同步数据为空";
|
}
|
InoutAppoint appoint;
|
for (InoutAppoint inoutAppoint : list) {
|
appoint = inoutAppointService.getInoutAppointById(inoutAppoint.getId(), inoutAppoint.getDeptId());
|
if(null != appoint){
|
log.warn("----------当前预约信息已存在,不更新={}---------", appoint);
|
continue;
|
}
|
|
//新增,状态为待审核
|
inoutAppoint.setStatus(OrderStatus.Status_10.getCode());
|
inoutAppoint.setCompanyId(param.getCompanyId());
|
inoutAppointService.saveOrUpInoutAppoint(inoutAppoint);
|
}
|
return "success";
|
}
|
|
}
|