package com.xzx.gc.order.controller; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.convert.Convert; import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.xzx.gc.common.Result; import com.xzx.gc.common.constant.CommonEnum; import com.xzx.gc.common.constant.Constants; import com.xzx.gc.common.constant.OrderEnum; import com.xzx.gc.common.dto.CommonDto; import com.xzx.gc.common.dto.SimplePage; import com.xzx.gc.common.dto.log.OperationAppLog; import com.xzx.gc.common.exception.RestException; import com.xzx.gc.common.request.BaseController; import com.xzx.gc.common.utils.*; import com.xzx.gc.entity.*; import com.xzx.gc.model.JsonResult; import com.xzx.gc.model.admin.PayStorageModel; import com.xzx.gc.model.admin.StorageUserModel; import com.xzx.gc.model.pay.MoneyAuditDto; import com.xzx.gc.model.system.ConfigInfoReq; import com.xzx.gc.model.system.ConfigInfoVo; import com.xzx.gc.order.dto.*; import com.xzx.gc.order.mapper.*; import com.xzx.gc.order.service.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import tk.mybatis.mapper.entity.Example; import javax.servlet.http.HttpServletRequest; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; /** * @author :zz */ @RestController @Api(tags = {"入库管理"}) @Validated @Slf4j public class StorageController extends BaseController { @Autowired private OrderClockInService orderClockInService; @Autowired private CityPartnerService cityPartnerService; @Autowired private OrderStorageInfoMapper orderStorageInfoMapper; @Autowired private AccountService accountService; @Autowired private OrderClockInMapper orderClockInMapper; @Autowired private OrderBatchInfoMapper orderBatchInfoMapper; @Autowired private OrderStorageDetailMapper orderStorageDetailMapper; @Autowired private StorageService storageService; @Autowired private OrderMapper orderMapper; @Autowired private ConfigService configService; @Autowired private RedisUtil redisUtil; @Autowired private OtherUserMapper otherUserMapper; @Autowired private BusinessUtil businessUtil; @Autowired private UserService userService; @PostMapping("/storage/rk/list") @ApiOperation(value = "入库员新任务列表") public Result> rkList(HttpServletRequest request, @RequestBody SimplePage simplePage) { Result> result = new Result(); List list = new ArrayList<>(); OrderStorageInfo orderStorageInfo = new OrderStorageInfo(); orderStorageInfo.setStorageStatus(Convert.toShort(OrderEnum.入库检验中.getValue())); String userId = getUserId(request); OtherUserInfo otherUserInfo = otherUserMapper.selectByPrimaryKey(userId); //仓库或打包站id Integer sysorageId = null; if (otherUserInfo.getUserType().equals(CommonEnum.打包员.getValue())||otherUserInfo.getUserType().equals(CommonEnum.打包站运营员.getValue())) { CityPartner byuserId = cityPartnerService.findByuserId(otherUserInfo.getUserId(), OrderEnum.打包站.getValue()); if (byuserId != null) { sysorageId = byuserId.getId(); orderStorageInfo.setSysStorageId(Convert.toLong(sysorageId)); orderStorageInfo.setSysStorageType(Convert.toShort(OrderEnum.打包站.getValue())); } } else if (otherUserInfo.getUserType().equals(CommonEnum.入库员.getValue())) { sysorageId = Convert.toInt(otherUserInfo.getStorageId()); orderStorageInfo.setSysStorageType(Convert.toShort(OrderEnum.仓库.getValue())); orderStorageInfo.setSysStorageId(Convert.toLong(sysorageId)); } PageHelper.startPage(simplePage.getPageNo(), simplePage.getPageSize()); List select = orderStorageInfoMapper.select(orderStorageInfo); if (CollUtil.isNotEmpty(select)) { for (OrderStorageInfo info : select) { StorageRkResDto storageRkResDto = new StorageRkResDto(); BeanUtils.copyProperties(info, storageRkResDto); //地称信息 Example example = new Example(OrderBatchInfo.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("orderId", info.getOrderId()); OrderBatchInfo orderBatchInfo = orderBatchInfoMapper.selectOneByExample(example); if (orderBatchInfo != null) { //载货打卡时间 storageRkResDto.setCreateTime(DateUtil.parseDateTime(orderBatchInfo.getCreateTime()).toString(DateUtils.DATE_FORMAT_HM)); storageRkResDto.setWeight(orderBatchInfo.getWeight()); Example example1 = new Example(OrderClockIn.class); Example.Criteria criteria1 = example1.createCriteria(); criteria1.andEqualTo("userId", orderBatchInfo.getUserId()); criteria1.andCondition("substring_index(create_time,' ',1)=", StrUtil.split(orderBatchInfo.getCreateTime(), " ")[0]); OrderClockIn orderClockIn = orderClockInMapper.selectOneByExample(example1); if (orderClockIn != null) { storageRkResDto.setEmptyWeight(orderClockIn.getWeight()); } } if (StrUtil.isBlank(storageRkResDto.getWeight())) { storageRkResDto.setWeight(Convert.toStr(Constants.WEIGHT_INIT)); } if (StrUtil.isBlank(storageRkResDto.getEmptyWeight())) { storageRkResDto.setEmptyWeight(Convert.toStr(Constants.WEIGHT_INIT)); } list.add(storageRkResDto); } } PageInfo pageInfo = new PageInfo(list); int i = storageService.countCompleteOrder(userId); pageInfo.setNavigatePages(i); result.setData(pageInfo); return result; } @PostMapping("/storage/rk/detail") @ApiOperation(value = "入库员新任务详情", notes = "id:入库ID") public Result rkDetailList(HttpServletRequest request, @RequestBody CommonDto commonDto) { Result result = new Result(); String storageId = commonDto.getId(); LogUtils.setTraceId(LogUtils.TRACE_ORDER_ID, storageId); RkDto rk = new RkDto(); List orderItemDtos = new ArrayList<>(); OrderStorageDetailInfo orderStorageDetailInfo = new OrderStorageDetailInfo(); orderStorageDetailInfo.setStorageId(storageId); orderStorageDetailInfo.setFlag(OrderEnum.回收型.getValue()); List select = orderStorageDetailMapper.select(orderStorageDetailInfo); //1为上门 2为定点 int type = 1; OrderStorageInfo orderStorageInfo = orderStorageInfoMapper.selectByPrimaryKey(storageId); String orderId = orderStorageInfo.getOrderId(); String s = orderId.split(",")[0]; OrderInfo orderInfo = orderMapper.selectByPrimaryKey(s); Long storeId = orderInfo.getStoreId(); if (storeId != null) { type = 2; } int usertype = 1; String userId = getUserId(request); OtherUserInfo otherUserInfo = otherUserMapper.selectByPrimaryKey(userId); String packageId = null; if (otherUserInfo.getUserType().equals(CommonEnum.打包员.getValue())||otherUserInfo.getUserType().equals(CommonEnum.打包站运营员.getValue())) { usertype = 2; packageId = otherUserInfo.getPartnerId(); }else if(otherUserInfo.getUserType().equals(CommonEnum.入库员.getValue())){ packageId=otherUserInfo.getStorageId(); } //设置分类信息 String receiver = orderStorageInfo.getReceiver(); storageService.setItem(rk, orderItemDtos, select, usertype, packageId); rk.setStorageUserId(userId); rk.setStorageId(storageId); //地称信息 BigDecimal recycleMoney = orderStorageInfo.getRecycleMoney(); rk.setMoney(Convert.toStr(recycleMoney)); Example example = new Example(OrderBatchInfo.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("orderId", orderStorageInfo.getOrderId()); OrderBatchInfo orderBatchInfo = orderBatchInfoMapper.selectOneByExample(example); if (orderBatchInfo != null) { rk.setWeight(orderBatchInfo.getWeight()); } if (StrUtil.isBlank(rk.getWeight())) { rk.setWeight(Convert.toStr(Constants.WEIGHT_INIT)); } result.setData(rk); return result; } @PostMapping("/storage/rk/code/detail") @ApiOperation(value = "手动扫码入库新任务详情") public Result rkCodeDetailList(HttpServletRequest request, @RequestBody CommonDto commonDto) { JSONObject parse = null; //回收员ID String userId = ""; Long timestamp = null; try { String extra = commonDto.getExtra(); extra = StrUtil.removePrefix(extra, ","); String decrypt = SecurityUtil.decrypt(Constants.PWD_DECRET, extra); parse = JSONUtil.parseObj(decrypt); userId = parse.getStr("userId"); // devCode = parse.getStr("devCode"); timestamp = parse.getLong("timestamp"); } catch (Exception e) { ExceptionUtils.err("解码失败", e); } Date date = new Date(timestamp); if(SpringUtil.isDev()) { if (DateUtil.between(date, new Date(), DateUnit.HOUR) > 30) { throw new RestException("二维码已过期"); } }else { if (DateUtil.between(date, new Date(), DateUnit.SECOND) > 30) { throw new RestException("二维码已过期"); } } Result rkDtoResult=new Result<>(); //判断扫码开关是否打开 关闭的情况下是否用户入库失败三次 String userId1 = getUserId(request); //入库员或打包员 OtherUserInfo otherUserInfo = otherUserMapper.selectByPrimaryKey(userId1); //回收员所属的合伙人 String partnerId = otherUserMapper.selectByPrimaryKey(userId).getPartnerId(); if (otherUserInfo.getUserType().equals(CommonEnum.打包员.getValue())||otherUserInfo.getUserType().equals(CommonEnum.打包站运营员.getValue())) { String packageId =otherUserInfo.getPartnerId(); /* 判断扫码的入库员所属的合伙人是否与回收员一致 */ String packingStation = cityPartnerService.findById(Convert.toInt(packageId)).getPackingStation(); if(!partnerId.equals(packingStation)){ return Result.error(-1, "禁止扫码"); } rkDtoResult = storageService.rkDetail(request, userId, 2, packageId); } else { ConfigInfoReq configInfoReq = new ConfigInfoReq(); configInfoReq.setConfigTypeCode("CODE_SCAN_RK"); List configInfoVos = configService.configInfoQuery(configInfoReq); if (CollUtil.isNotEmpty(configInfoVos) && Constants.OPEN.equals(configInfoVos.get(0).getConfigValue())) { if(!partnerId.equals(otherUserInfo.getPartnerId())){ return Result.error(-1, "禁止扫码"); } rkDtoResult = storageService.rkDetail(request, userId, 1, otherUserInfo.getStorageId()); } else { if (orderClockInService.notClock(userId)) { rkDtoResult = storageService.rkDetail(request, userId, 1, otherUserInfo.getStorageId()); }else { //开关关闭的情况下 String errNum = redisUtil.hget(Constants.REDIS_ORDER_KEY + "storage:errcount", userId); if (errNum != null && Convert.toInt(errNum) >= 3) { rkDtoResult = storageService.rkDetail(request, userId, 1, otherUserInfo.getStorageId()); } else { return Result.error(-1, "禁止扫码"); } } } } if(rkDtoResult.getCode()==0){ String mobilePhone = userService.findOtherByUserId(getUserId(request),1); OperationAppLog build = OperationAppLog.builder().appPrograme(getFrontClient(request)).opreateName(mobilePhone) .methodName(Constants.ORDER_MODUL_NAME).operateAction("手动扫码入库-"+rkDtoResult.getData().getStorageId()).build(); mqUtil.sendApp(build); } return rkDtoResult; } @PostMapping("/storage/rk/statistics") @ApiOperation(value = "入库统计(含回收员与入库员与打包员)") public Result rkStatistics(HttpServletRequest request, @RequestBody RkStatisDto rkStatisDto) { Result res = new Result<>(); String userType = rkStatisDto.getUserType(); String userId = getUserId(request); RkStatisticsDto rkStatisticsDto = storageService.statistics(userId, userType,rkStatisDto.getData(),rkStatisDto.getReceiver()); res.setData(rkStatisticsDto); return res; } @PostMapping("/storage/rk") @ApiOperation(value = "入库") public Result rk(HttpServletRequest request, @RequestBody RkDto rkDto) { rkDto.setVersion(getVersion(request)); //处理金额和重量 BigDecimal money = rkDto.getStorageMoney(); if (money != null && money.compareTo(BigDecimal.ZERO) != 0) { String money1 = businessUtil.changeMoney(Convert.toStr(money)); rkDto.setStorageMoney(Convert.toBigDecimal(money1)); } String weight = rkDto.getStorageWeight(); if (StrUtil.isNotBlank(weight)) { String s = businessUtil.changeWeight(weight); rkDto.setStorageWeight(s); } LogUtils.setTraceId(LogUtils.TRACE_ORDER_ID, rkDto.getStorageId()); storageService.rk(rkDto); String mobilePhone = userService.findOtherByUserId(getUserId(request),1); OperationAppLog build = OperationAppLog.builder().appPrograme(getFrontClient(request)).opreateName(mobilePhone) .methodName(Constants.ORDER_MODUL_NAME).operateAction("入库-"+rkDto.getStorageId()).build(); mqUtil.sendApp(build); return Result.success(); } }