新增药液管理

master
FCD 4 days ago
parent 1895ebc6d2
commit 61b66b1980

@ -4,7 +4,7 @@ import com.op.common.core.web.controller.BaseController;
import com.op.common.core.web.page.TableDataInfo;
import com.op.common.security.annotation.RequiresPermissions;
import com.op.plan.domain.BaseProduct;
import com.op.plan.service.IBaseProductService;
import com.op.plan.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@ -0,0 +1,75 @@
package com.op.plan.controller;
import com.op.common.core.domain.R;
import com.op.common.core.web.controller.BaseController;
import com.op.common.core.web.domain.AjaxResult;
import com.op.common.core.web.page.TableDataInfo;
import com.op.common.security.utils.SecurityUtils;
import com.op.plan.domain.MedicationDetailPo;
import com.op.plan.domain.MedicationPo;
import com.op.plan.domain.MedicationQuery;
import com.op.plan.service.IProMedicationService;
import com.op.system.api.model.SapProOrder;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* remark
*
* @author 019117
* @date
*/
@RestController
@RequestMapping("/medication")
@RequiredArgsConstructor
public class ProMedicationController extends BaseController {
private final IProMedicationService proMedicationService;
//同步药液订单
@PostMapping("/syncOrder")
public AjaxResult syncMedicationOrder(@RequestBody MedicationQuery query){
proMedicationService.syncMedicationOrder(query);
return success();
}
//修改药液订单
@PutMapping
public AjaxResult updateMedication(@RequestBody MedicationPo params){
params.setUpdateBy(SecurityUtils.getUsername());
proMedicationService.updateMedication(params);
return success();
}
@GetMapping("/list")
public TableDataInfo selectMedicationList(MedicationQuery query){
startPage();
List<MedicationPo> list = proMedicationService.selectMedicationList(query);
return getDataTable(list);
}
@GetMapping("/detail/list")
public AjaxResult selectMedicationDetailList(MedicationQuery query){
List<MedicationDetailPo> list = proMedicationService.selectMedicationDetailList(query);
return AjaxResult.success(list);
}
@PutMapping("/detail/list")
public AjaxResult updateMedicationDetailList(@RequestBody List<MedicationDetailPo> list){
proMedicationService.updateMedicationDetailList(list);
return AjaxResult.success();
}
@PostMapping("/reportSapMedication")
public AjaxResult reportSapMedication(@RequestBody List<MedicationPo> params){
proMedicationService.reportSapMedication(params);
return AjaxResult.success();
}
}

@ -0,0 +1,41 @@
package com.op.plan.domain;
import com.op.common.core.web.domain.BaseEntity;
import lombok.Data;
/**
* remark
*
* @author 019117
* @date
*/
@Data
public class MedicationDetailPo extends BaseEntity {
private String id;
private String orderCode;
private String itemCode;
private String materialCode;
private String materialName;
private String factory;
private String location;
private String productionDate;
private String amount;
private String inputAmount;
private String unit;
private String backFlag;
}

@ -0,0 +1,51 @@
package com.op.plan.domain;
import com.op.common.core.web.domain.BaseEntity;
import lombok.Data;
import java.util.Date;
/**
* remark
*
* @author 019117
* @date
*/
@Data
public class MedicationPo extends BaseEntity {
private Integer id;
private String orderCode;
private String workOrderCode;
private String materialCode;
private String materialName;
private String amount;
private String reportAmount;
private String unit;
private String status;
private String productionDate;
private String factory;
private Date sapTime;
private String sapRemark;
private String realAmount;
private String workTime;
private String useNum;
}

@ -0,0 +1,40 @@
package com.op.plan.domain;
import lombok.Data;
import java.util.Date;
/**
* remark
*
* @author 019117
* @date
*/
@Data
public class MedicationQuery {
//订单号
private String workOrderCode;
private String orderCode;
//开始时间
private String startTime;
//结束时间
private String endTime;
//生产日期
private String proDate;
//物料编码
private String materialCode;
//工厂
private String factory;
}

@ -0,0 +1,23 @@
package com.op.plan.mapper;
import com.op.plan.domain.MedicationDetailPo;
import com.op.plan.domain.MedicationQuery;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* remark
*
* @author 019117
* @date
*/
public interface ProMedicationDetailMapper {
void batchInsertMedicationDetail(List<MedicationDetailPo> po);
List<MedicationDetailPo> selectMedicationDetailList(MedicationQuery query);
void batchUpdateMedicationDetail( @Param("list") List<MedicationDetailPo> list, @Param("updateBy") String updateBy);
}

@ -0,0 +1,22 @@
package com.op.plan.mapper;
import com.op.plan.domain.MedicationPo;
import com.op.plan.domain.MedicationQuery;
import java.util.List;
/**
* remark
*
* @author 019117
* @date
*/
public interface ProMedicationMapper {
void insertMedication(MedicationPo po);
void updateMedication(MedicationPo po);
List<MedicationPo> selectMedicationList(MedicationQuery po);
}

@ -0,0 +1,30 @@
package com.op.plan.service;
import com.op.plan.domain.MedicationDetailPo;
import com.op.plan.domain.MedicationPo;
import com.op.plan.domain.MedicationQuery;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* remark
*
* @author 019117
* @date
*/
public interface IProMedicationService {
void syncMedicationOrder(MedicationQuery query);
void updateMedication(MedicationPo params);
List<MedicationPo> selectMedicationList(MedicationQuery query);
List<MedicationDetailPo> selectMedicationDetailList(MedicationQuery query);
void updateMedicationDetailList(List<MedicationDetailPo> list);
void reportSapMedication(List<MedicationPo> params);
}

@ -0,0 +1,198 @@
package com.op.plan.service.impl;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.op.common.core.domain.R;
import com.op.common.core.utils.DateUtils;
import com.op.common.security.utils.SecurityUtils;
import com.op.plan.domain.MedicationDetailPo;
import com.op.plan.domain.MedicationPo;
import com.op.plan.domain.MedicationQuery;
import com.op.plan.mapper.ProMedicationDetailMapper;
import com.op.plan.mapper.ProMedicationMapper;
import com.op.plan.service.IProMedicationService;
import com.op.system.api.RemoteSapService;
import com.op.system.api.domain.sap.SapMaterialPreparation;
import com.op.system.api.domain.sap.SapRFW;
import com.op.system.api.domain.sap.SapShopOrderQuery;
import com.op.system.api.model.SapProOrder;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
/**
* remark
*
* @author 019117
* @date
*/
@Service
@RequiredArgsConstructor
public class ProMedicationServiceImpl implements IProMedicationService {
private final RemoteSapService remoteSapService;
private final ProMedicationMapper proMedicationMapper;
private final ProMedicationDetailMapper proMedicationDetailMapper;
@Override
@DS("#header.poolName")
public void syncMedicationOrder(MedicationQuery query) {
SapShopOrderQuery syncQuery = new SapShopOrderQuery();
Map<String, Object> dataParams = new HashMap<>();
dataParams.put("planDateStart", query.getStartTime());
dataParams.put("planDateEnd", query.getEndTime());
syncQuery.setParams(dataParams);
syncQuery.setWerk(query.getFactory());
R<List<SapProOrder>> result = remoteSapService.shopOrderSync(syncQuery);
List<SapProOrder> orderList = result.getData();
for (SapProOrder order : orderList) {
//只取药液订单类型为LJ01编号是208和209开头
if ("LJ01".equals(order.getOrderType()) && ( order.getProdCode().startsWith("0000000208") || order.getProdCode().startsWith("0000000209") ) ){
MedicationPo po = new MedicationPo();
String proDate = DateUtils.parseDateToStr("yyyy-MM-dd",order.getPlanProDate());
po.setOrderCode(order.getOrderCode());
po.setWorkOrderCode(order.getWorkerOrder());
po.setOrderCode(order.getOrderCode());
po.setMaterialCode(order.getProdCode());
po.setMaterialName(order.getProdDesc());
po.setAmount(order.getQuantity().toString());
po.setUnit(order.getUnit());
po.setStatus("0");
po.setProductionDate(proDate);
po.setFactory(order.getPlanFactoryCode());
//判断是否已经存在订单 (订单+物料+时间)
MedicationQuery medicationQuery = new MedicationQuery();
medicationQuery.setMaterialCode(order.getProdCode());
medicationQuery.setWorkOrderCode(order.getWorkerOrder());
medicationQuery.setOrderCode(order.getOrderCode());
medicationQuery.setProDate(proDate);
List<MedicationPo> selectPo = proMedicationMapper.selectMedicationList(medicationQuery);
if (selectPo.isEmpty()){
po.setCreateBy(SecurityUtils.getUsername());
proMedicationMapper.insertMedication(po);
//获取药液配方
List<MedicationDetailPo> detailList = getMedicationDetailPoList(order.getOrderCode());
proMedicationDetailMapper.batchInsertMedicationDetail(detailList);
}
}
}
}
private List<MedicationDetailPo> getMedicationDetailPoList(String orderCode){
List<MedicationDetailPo> detailList = new ArrayList<>();
List<SapMaterialPreparation> detailResult = remoteSapService.materialPreparation(orderCode).getData();
if (!detailResult.isEmpty()) {
for (SapMaterialPreparation detail : detailResult){
MedicationDetailPo detailPo = new MedicationDetailPo();
detailPo.setOrderCode(detail.getAUFNR());
detailPo.setItemCode(detail.getRSPOS());
detailPo.setMaterialCode(detail.getMATNR());
detailPo.setMaterialName(detail.getMAKTX());
detailPo.setFactory(detail.getWERKS());
detailPo.setLocation(detail.getLGORT());
detailPo.setProductionDate(detail.getBDTER());
detailPo.setAmount(detail.getBDMNG());
detailPo.setUnit(detail.getMEINS());
detailPo.setInputAmount(detail.getERFMG());
detailPo.setBackFlag(detail.getRGEKZ());
detailList.add(detailPo);
}
}
return detailList;
}
@Override
@DS("#header.poolName")
public void updateMedication(MedicationPo params) {
proMedicationMapper.updateMedication(params);
}
@Override
@DS("#header.poolName")
public List<MedicationPo> selectMedicationList(MedicationQuery query) {
return proMedicationMapper.selectMedicationList(query);
}
@Override
@DS("#header.poolName")
public List<MedicationDetailPo> selectMedicationDetailList(MedicationQuery query) {
return proMedicationDetailMapper.selectMedicationDetailList(query);
}
@Override
@DS("#header.poolName")
public void updateMedicationDetailList(List<MedicationDetailPo> list) {
proMedicationDetailMapper.batchUpdateMedicationDetail(list,SecurityUtils.getUsername());
}
@Override
@DS("#header.poolName")
public void reportSapMedication(List<MedicationPo> params) {
for (MedicationPo po : params) {
//获取损耗物料
MedicationQuery query = new MedicationQuery();
query.setOrderCode(po.getOrderCode());
List<MedicationDetailPo> detailList = proMedicationDetailMapper.selectMedicationDetailList(query);
if (detailList.isEmpty()){
throw new RuntimeException("订单"+po.getOrderCode()+"的损耗物料为空!");
}
SapRFW sap = new SapRFW();
sap.setAufnr(po.getOrderCode());
sap.setGamng(po.getReportAmount());
sap.setAnzma("111.00");
sap.setBudat(DateUtils.parseDateToStr("yyyyMMdd", new Date()));
double allTime = Double.parseDouble(po.getWorkTime()) * Double.parseDouble(po.getUseNum());
SapRFW.lt_gs lts = new SapRFW.lt_gs();
lts.setConf_activity1(po.getWorkTime());
lts.setConf_activity2(Double.toString(allTime));
lts.setConf_activity3(po.getWorkTime());
lts.setConf_activity4(Double.toString(allTime));
sap.setLt_gs(lts);
List<SapRFW.lt_hw> hwList = new ArrayList<>();
for (MedicationDetailPo detailPo : detailList) {
SapRFW.lt_hw lt_hw = new SapRFW.lt_hw();
lt_hw.setMaterial(detailPo.getMaterialCode());
lt_hw.setRspos(detailPo.getItemCode());
lt_hw.setEntry_qnt(detailPo.getInputAmount());
}
sap.setLt_hwList(hwList);
R r = remoteSapService.sapRFWOrder(sap);
if (r.getCode() == 200) {
po.setStatus("1");
}else {
po.setStatus("2");
}
po.setSapTime(new Date());
po.setSapRemark(r.getMsg());
po.setRealAmount(po.getReportAmount());
po.setUpdateBy(SecurityUtils.getUsername());
proMedicationMapper.updateMedication(po);
}
}
}

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.op.plan.mapper.ProMedicationDetailMapper">
<insert id="batchInsertMedicationDetail" parameterType="com.op.plan.domain.MedicationDetailPo">
insert into pro_medication_order_detail (order_code, item_code, material_code, material_name, factory, location, production_date, amount, input_amount, unit, back_flag, create_by, create_time)
values
<foreach collection="list" item="item" index="index" separator=",">
(#{item.orderCode}, #{item.itemCode}, #{item.materialCode}, #{item.materialName},
#{item.factory}, #{item.location}, #{item.productionDate}, #{item.amount}, #{item.inputAmount},
#{item.unit}, #{item.backFlag}, #{item.createBy}, GETDATE())
</foreach>
</insert>
<select id="selectMedicationDetailList" parameterType="com.op.plan.domain.MedicationQuery" resultType="com.op.plan.domain.MedicationDetailPo">
select
id,
order_code as orderCode,
item_code as itemCode,
material_code as materialCode,
material_name as materialName,
factory,
location,
production_date as productionDate,
amount,
input_amount as inputAmount,
unit,
back_flag as backFlag
from pro_medication_order_detail
<where>
<if test="orderCode != null and orderCode != ''">and order_code = #{orderCode}</if>
<if test="materialCode != null and materialCode != ''">and material_code like concat('%', #{materialCode}, '%')</if>
</where>
order by item_code
</select>
<update id="batchUpdateMedicationDetail" parameterType="com.op.plan.domain.MedicationDetailPo">
<foreach collection="list" item="item" index="index" open="" close="" separator=";">
update pro_medication_order_detail
<set>
<if test="item.inputAmount != null">input_amount = #{item.inputAmount},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
update_time = GETDATE()
</set>
where id = #{item.id}
</foreach>
</update>
</mapper>

@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.op.plan.mapper.ProMedicationMapper">
<insert id="insertMedication" parameterType="com.op.plan.domain.MedicationPo">
INSERT INTO pro_medication_order
(work_order_code , order_code, factory, material_code , material_name , amount , report_amount , unit , status , production_date , create_by , create_time)
VALUES
(#{workOrderCode}, #{orderCode}, #{factory}, #{materialCode}, #{materialName}, #{amount}, #{reportAmount}, #{unit}, #{status}, #{productionDate}, #{createBy}, GETDATE())
</insert>
<update id="updateMedication" parameterType="com.op.plan.domain.MedicationPo">
UPDATE pro_medication_order
SET
<if test="amount != null and amount != ''">
amount = #{amount},
</if>
<if test="reportAmount != null and reportAmount != ''">
report_amount = #{reportAmount},
</if>
<if test="status != null and status != ''">
status = #{status},
</if>
<if test="sapTime != null">
sap_time = #{sapTime},
</if>
<if test="sapRemark != null and sapRemark != ''">
sap_remark = #{sapRemark},
</if>
<if test="realAmount != null and realAmount != ''">
real_amount = #{realAmount},
</if>
<if test="workTime != null and workTime != ''">
work_time = #{workTime},
</if>
<if test="useNum != null and useNum != ''">
use_num = #{useNum},
</if>
<if test="updateBy != null and updateBy != ''">
update_by = #{updateBy},
</if>
update_time = GETDATE()
WHERE id = #{id}
</update>
<select id="selectMedicationList" parameterType="com.op.plan.domain.MedicationQuery" resultType="com.op.plan.domain.MedicationPo">
SELECT
id,
work_order_code workOrderCode,
order_code orderCode,
material_code materialCode,
material_name materialName,
amount ,
report_amount reportAmount,
unit ,
status ,
production_date productionDate,
sap_time sapTime,
sap_remark sapRemark,
work_time workTime,
use_num useNum,
real_amount realAmount
FROM pro_medication_order
<where>
<if test="workOrderCode != null and workOrderCode != ''">
AND work_order_code like CONCAT('%', #{workOrderCode}, '%')
</if>
<if test="materialCode != null and materialCode != ''">
AND material_code like CONCAT('%', #{materialCode}, '%')
</if>
<if test="orderCode != null and orderCode != ''">
AND order_code like CONCAT('%', #{orderCode}, '%')
</if>
<if test="proDate != null and proDate != ''">
AND production_date = #{proDate}
</if>
</where>
order by production_date desc
</select>
</mapper>
Loading…
Cancel
Save