| | |
| | | package com.nanometer.smartlab.email; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.nanometer.smartlab.entity.EmailStatus; |
| | | import com.nanometer.smartlab.entity.OpeWarehouseReserve; |
| | | import com.nanometer.smartlab.entity.SysReagent; |
| | | import com.nanometer.smartlab.entity.SysUser; |
| | | import com.nanometer.smartlab.entity.enumtype.EmailSendStatus; |
| | | import com.nanometer.smartlab.exception.BusinessException; |
| | | import com.nanometer.smartlab.exception.ExceptionEnumCode; |
| | | import com.nanometer.smartlab.service.*; |
| | | import com.nanometer.smartlab.util.EmailSend; |
| | | import com.nanometer.smartlab.util.HttpUtil; |
| | | import net.sf.cglib.asm.$ByteVector; |
| | | import org.apache.commons.lang.StringUtils; |
| | | import org.apache.http.message.BasicNameValuePair; |
| | | import org.apache.log4j.Logger; |
| | | import org.omg.CORBA.NameValuePair; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * Created by wjd on 18/6/18. |
| | |
| | | private OpeWarehouseReserveService opeWarehouseReserveService; |
| | | @Resource |
| | | private SysUserService userService; |
| | | @Resource |
| | | private SysSupplierService sysSupplierService; |
| | | |
| | | @Scheduled(fixedDelayString = "${emailSend.schedule.delay}") |
| | | public void EmailSendSchedule(){ |
| | |
| | | |
| | | |
| | | // @Scheduled(cron = "0/5 * * * * ?") //每隔5秒执行一次 |
| | | @Scheduled(cron = "0 0/3 * * * ?") //每天8点执行一次 |
| | | @Scheduled(cron = "0 0 8 * * ?")//每天8点执行一次 |
| | | public void EmailSendStock(){ |
| | | //收件人为人员角色为库管员的邮箱 |
| | | List<String> revicerList = userService.getLibrarianEmail(); |
| | |
| | | } |
| | | } |
| | | } |
| | | StringBuffer content = new StringBuffer("<html><body>"); |
| | | content.append("<div style=\"line-height:1.7;color:#000000;font-size:14px;font-family:Arial\">"); |
| | | content.append("<table border=\"1\">"); |
| | | content.append("<tbody>"); |
| | | content.append("<tr>"); |
| | | content.append("<th>试剂名称</th>"); |
| | | content.append("<th>产品编号</th>"); |
| | | content.append("<th>CAS</th>"); |
| | | content.append("<th>试剂类型</th>"); |
| | | content.append("<th>供应商</th>"); |
| | | content.append("<th>厂家</th>"); |
| | | content.append("<th>规格</th>"); |
| | | content.append("<th>包装</th>"); |
| | | content.append("<th>安全库存</th>"); |
| | | content.append("<th>实际库存</th>"); |
| | | content.append("</tr>"); |
| | | for (SysReagent sysReagent : sysReagentList){ |
| | | if(sysReagentList.size() > 0 && revicerList.size() > 0 ){ |
| | | StringBuffer content = new StringBuffer("<html><body>"); |
| | | content.append("<div style=\"line-height:1.7;color:#000000;font-size:14px;font-family:Arial\">"); |
| | | content.append("<table border=\"1\">"); |
| | | content.append("<tbody>"); |
| | | content.append("<tr>"); |
| | | content.append("<td>"+sysReagent.getName()+"</td>"); |
| | | content.append("<td>"+sysReagent.getProductSn()+"</td>"); |
| | | content.append("<td>"+sysReagent.getCas()+"</td>"); |
| | | |
| | | content.append("<td>"+sysReagent.getReagentType()+"</td>");// |
| | | content.append("<td>"+sysReagent.getSupplierName()+"</td>"); |
| | | |
| | | content.append("<td>"+sysReagent.getProductHomeName()+"</td>"); |
| | | |
| | | content.append("<td>"+sysReagent.getReagentFormat()+"</td>");// |
| | | |
| | | content.append("<td>"+sysReagent.getReagentUnit()+"</td>");// |
| | | content.append("<td>"+sysReagent.getSafetynum()+"</td>"); |
| | | content.append("<td>"+sysReagent.getActualnum()+"</td>"); |
| | | content.append("<th>试剂名称</th>"); |
| | | content.append("<th>产品编号</th>"); |
| | | content.append("<th>CAS</th>"); |
| | | content.append("<th>试剂类型</th>"); |
| | | content.append("<th>供应商</th>"); |
| | | content.append("<th>厂家</th>"); |
| | | content.append("<th>规格</th>"); |
| | | content.append("<th>包装</th>"); |
| | | content.append("<th>安全库存</th>"); |
| | | content.append("<th>实际库存</th>"); |
| | | content.append("</tr>"); |
| | | } |
| | | content.append("</tbody></table></div>"); |
| | | content.append("</body></html>"); |
| | | for (SysReagent sysReagent : sysReagentList){ |
| | | content.append("<tr>"); |
| | | content.append("<td>"+sysReagent.getName()+"</td>"); |
| | | content.append("<td>"+sysReagent.getProductSn()+"</td>"); |
| | | content.append("<td>"+sysReagent.getCas()+"</td>"); |
| | | |
| | | try { |
| | | // EmailSend.sendArrivalEmail(revicerList,content.toString()); |
| | | // 发送成功,更新邮件发送状态为:已发送 |
| | | } catch (BusinessException e) { |
| | | // 发送失败,更新邮件发送状态为:发送失败 |
| | | logger.warn("操作失败。", e); |
| | | } catch (Exception e) { |
| | | logger.error(e); |
| | | content.append("<td>"+sysReagent.getReagentType()+"</td>");// |
| | | content.append("<td>"+sysReagent.getSupplierName()+"</td>"); |
| | | |
| | | content.append("<td>"+sysReagent.getProductHomeName()+"</td>"); |
| | | |
| | | content.append("<td>"+sysReagent.getReagentFormat()+"</td>");// |
| | | |
| | | content.append("<td>"+sysReagent.getReagentUnit()+"</td>");// |
| | | content.append("<td>"+sysReagent.getSafetynum()+"</td>"); |
| | | content.append("<td>"+sysReagent.getActualnum()+"</td>"); |
| | | content.append("</tr>"); |
| | | } |
| | | content.append("</tbody></table></div>"); |
| | | content.append("</body></html>"); |
| | | |
| | | try { |
| | | EmailSend.sendArrivalEmail(revicerList,content.toString(),"-待补货试剂"); |
| | | // 发送成功,更新邮件发送状态为:已发送 |
| | | } catch (BusinessException e) { |
| | | // 发送失败,更新邮件发送状态为:发送失败 |
| | | logger.warn("操作失败。", e); |
| | | } catch (Exception e) { |
| | | logger.error(e); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | @Value("${reagent.detail.price.api}") |
| | | private String reagentApi; |
| | | |
| | | private final static String send_supplier_name = "国药集团化学试剂苏州有限公司"; |
| | | private final static BigDecimal SALE_85 = BigDecimal.valueOf(0.85); |
| | | private final static Map discountMap = new HashMap<BigDecimal,String>(){{ |
| | | put(SALE_85, "85折价格"); |
| | | }}; |
| | | |
| | | /** |
| | | * @Description: 姑苏实验室 发给admin管理员邮箱 国药试剂(价格不同的)信息 执行时间 :每天早上2点 |
| | | * @date 2021/8/19 9:06 |
| | | */ |
| | | @Scheduled(cron = "0 0 2 * * ?") |
| | | // @Scheduled(cron = "0/5 * * * * ?") //每隔5秒执行一次 |
| | | public void ReagentPriceSend(){ |
| | | //0.限制在姑苏实验室 |
| | | if (StringUtils.isBlank(reagentApi) || reagentApi.length() == 0) return; |
| | | |
| | | try { |
| | | //1.获取管理员邮箱 |
| | | SysUser admin = userService.getSysUserByAccount("admin"); |
| | | if (admin == null ||StringUtils.isBlank(admin.getEmail())) throw new BusinessException(ExceptionEnumCode.PARAM_NULL,"找不到管理员或者管理员邮箱信息"); |
| | | |
| | | //2.获取国药试剂 |
| | | Long supplierId = sysSupplierService.getSysSupplierIdByname(send_supplier_name); |
| | | if (supplierId==null) |
| | | throw new BusinessException(ExceptionEnumCode.PARAM_NO_EXIST, "没有找到与(" + send_supplier_name + ")相关供应商,请检查最近信息更新"); |
| | | |
| | | List<SysReagent> guoyao_reagents = sysReagentService.getSysReagentListNew(null, null, supplierId, 1, null, null, null); |
| | | if (guoyao_reagents.size() < 1) |
| | | throw new BusinessException(ExceptionEnumCode.PARAM_NULL, "供应商:" + send_supplier_name + ",没有查询到相关试剂"); |
| | | |
| | | List<JSONObject> sendDataList = new ArrayList<>(); |
| | | for (SysReagent reagent : guoyao_reagents) { |
| | | String productSn = reagent.getProductSn(); |
| | | List params = new ArrayList<BasicNameValuePair>() {{ |
| | | add(new BasicNameValuePair("goodsErpCode", productSn)); |
| | | }}; |
| | | String res = HttpUtil.doGet(reagentApi, params); |
| | | JSONObject resJson = JSONObject.parseObject(res); |
| | | JSONArray data = resJson.getJSONArray("data"); |
| | | JSONObject dataJson = data.getJSONObject(0); |
| | | Integer totalRows = dataJson.getInteger("totalRows"); |
| | | if (totalRows != 1) continue; |
| | | |
| | | JSONArray listApiGoods = dataJson.getJSONArray("listApiGoods"); |
| | | if (listApiGoods.size() != 1) logger.info("产品编号:" + productSn + ",接口查询到多个数据,无法判断"); |
| | | |
| | | JSONObject goodJson = listApiGoods.getJSONObject(0); |
| | | String goodsName = goodJson.getString("goodsName"); |
| | | BigDecimal goodsCostPrice = goodJson.getBigDecimal("goodsCostPrice"); |
| | | BigDecimal price = reagent.getPrice(); |
| | | //保留两位 |
| | | BigDecimal price_afterDiscount = SALE_85.multiply(goodsCostPrice).setScale(2, RoundingMode.HALF_UP); |
| | | if (price_afterDiscount.compareTo(price) > 0) { |
| | | sendDataList.add(new JSONObject() {{ |
| | | put("goodsName", goodsName); |
| | | put("goodsCostPrice", goodsCostPrice); |
| | | put("priceAfterDiscount", price_afterDiscount); |
| | | put("currentSystemPrice", price); |
| | | put("goodsCode", productSn); |
| | | }}); |
| | | } |
| | | } |
| | | //制作表格 |
| | | StringBuilder content = new StringBuilder("<html><body>"); |
| | | content.append("<div style=\"line-height:1.7;color:#000000;font-size:14px;font-family:Arial\">"); |
| | | content.append("<table border=\"1\">"); |
| | | content.append("<tbody>"); |
| | | content.append("<tr>"); |
| | | content.append("<th>产品编号</th>"); |
| | | content.append("<th>产品名称</th>"); |
| | | content.append("<th>官网售价</th>"); |
| | | content.append("<th>").append(discountMap.get(SALE_85)).append("</th>"); |
| | | content.append("<th>当前系统价格</th>"); |
| | | content.append("</tr>"); |
| | | for (JSONObject goodJson : sendDataList){ |
| | | content.append("<tr>") |
| | | .append("<td>").append(goodJson.getString("goodsCode")).append("</td>") |
| | | .append("<td>").append(goodJson.getString("goodsName")).append("</td>") |
| | | .append("<td>").append(goodJson.getBigDecimal("goodsCostPrice")).append("</td>") |
| | | .append("<td>").append(goodJson.getBigDecimal("priceAfterDiscount")).append("</td>") |
| | | .append("<td>").append(goodJson.getBigDecimal("currentSystemPrice")).append("</td>") |
| | | .append("</tr>"); |
| | | } |
| | | content.append("</tbody></table></div>"); |
| | | content.append("</body></html>"); |
| | | |
| | | |
| | | //发送邮件 |
| | | EmailSend.sendArrivalEmail(Collections.singletonList(admin.getEmail()),content.toString(),"-国药试剂价格变动"); |
| | | // 发送成功,更新邮件发送状态为:已发送 |
| | | |
| | | } catch (BusinessException e) { |
| | | e.printStackTrace(); |
| | | logger.warn(e.getMessage()); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | logger.warn("系统内部错误,请检查代码"); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | } |