1.list.stream().collect(Collectors.groupingBy(对象::对象的属性的get方法))的使用
对象
package com.icss.io.biz;
public class Student {
private String name;
private Integer age;
private Integer gride;
private Integer classs;
public Student() {
}
public Student(String name, Integer age, Integer gride, Integer classs) {
this.name = name;
this.age = age;
this.gride = gride;
this.classs = classs;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public Integer getGride() {
return gride;
}
public void setGride(Integer gride) {
this.gride = gride;
}
public Integer getClasss() {
return classs;
}
public void setClasss(Integer classs) {
this.classs = classs;
}
@Override
public String toString() {
return "Student{" +
"name='" + name + '\'' +
", age=" + age +
", gride=" + gride +
", classs=" + classs +
'}';
}
}
测试
package com.icss.io.ui;
import com.icss.io.biz.Student;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class TestStudent {
public static void main(String[] args) {
List<Student> list=new ArrayList<>();
Student stu1=new Student("小明",18,1,2);
Student stu2=new Student("小张",18,1,1);
Student stu3=new Student("小李",22,2,1);
Student stu4=new Student("小聂",19,2,2);
Student stu5=new Student("小欧",20,3,1);
Student stu6=new Student("小赵",16,3,2);
list.add(stu1);
list.add(stu2);
list.add(stu3);
list.add(stu4);
list.add(stu5);
list.add(stu6);
//测试分组函数的用法
Map<Integer,List<Student>> stuMap=list.stream().collect(Collectors.groupingBy(Student::getGride));
System.out.println(stuMap);
System.out.println(stuMap.get(1));
}
}
结果
总结: 该方法就是把对象的属性作为主键,然后以该属性创建一个map集合,值为满足该属性的对象
2.发送qq邮箱的java方法
java jar包
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
java 方法
public static void sendMail(String accepter,String title,String content) throws AddressException,MessagingException {
// 创建Properties 类用于记录邮箱的一些属性
final Properties props = new Properties();
// 表示SMTP发送邮件,必须进行身份验证
props.put("mail.smtp.auth", "true");
//此处填写SMTP服务器
props.put("mail.smtp.host", "smtp.qq.com");
//端口号,QQ邮箱端口587
props.put("mail.smtp.port", "587");
// 此处填写,写信人的账号
props.put("mail.user", "921495759@qq.com");
// 此处填写16位STMP口令
props.put("mail.password", "**********");
// 构建授权信息,用于进行SMTP进行身份验证
Authenticator authenticator = new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
// 用户名、密码
String userName = props.getProperty("mail.user");
String password = props.getProperty("mail.password");
return new PasswordAuthentication(userName, password);
}
};
// 使用环境属性和授权信息,创建邮件会话
Session mailSession = Session.getInstance(props, authenticator);
// 创建邮件消息
MimeMessage message = new MimeMessage(mailSession);
// 设置发件人
InternetAddress form = new InternetAddress(props.getProperty("mail.user"));
message.setFrom(form);
// 设置收件人的邮箱
InternetAddress to = new InternetAddress(accepter);
message.setRecipient(RecipientType.TO, to);
// 设置邮件标题
message.setSubject(title);
// 设置邮件的内容体
message.setContent(content, "text/html;charset=UTF-8");
// 最后当然就是发送邮件啦
Transport.send(message);
}
3.枚举方法的使用
package com.imooc.o2o.enums;
public enum ShopStateEnum {
CHECK(0, "审核中"), OFFLINE(-1, "非法店铺"), SUCCESS(1, "操作成功"), PASS(2, "审核通过"), INNER_ERROR(-1001, "内部系统错误"),
NULL_SHOPID(-1002, "shopId为空");
private int state;
private String stateInfo;
private ShopStateEnum(int state, String stateInfo) {
this.state = state;
this.stateInfo = stateInfo;
}
/**
* 依据传入的state返回相应的enum值
*/
public static ShopStateEnum stateOf(Integer state) {
for (ShopStateEnum stateEnum : values()) {
if (stateEnum.getState()==state) {
return stateEnum;
}
}
return null;
}
public int getState() {
return state;
}
public String getStateInfo() {
return stateInfo;
}
}
4.插入图片的方法
1.导入jar包
<dependency>
<groupId>net.coobird</groupId>
<artifactId>thumbnailator</artifactId>
<version>0.4.14</version>
</dependency>
2.方法步骤如下
2.1 获取店铺相关的id
private void addShopImage(Shop shop, File shopImage) {
//获取shop图片目录的相对值路径
String dest=PathUtil.getShopImagePath(shop.getShopId());
String shopImgAddr=ImageUtil.generateThumbnail(shopImage, dest);
shop.setShopImg(shopImgAddr);
}
2.2 PathUtil的getShopImagePath方法
package com.imooc.o2o.util;
public class PathUtil {
private static String seperator=System.getProperty("file.separator");
public static String getImageBasePath() {
String os=System.getProperty("os.name");
String basePath="";
if(os.toLowerCase().startsWith("win")) {
basePath="D:/Program Files/eclipse/image/" ;
}else {
basePath="home/eclipse/image/";
}
basePath=basePath.replace("/", seperator);
return basePath;
}
public static String getShopImagePath(long shopId) {
String imagePath="upload/item/shop/"+shopId+"/";
return imagePath.replace("/", seperator);
}
}
2.3 ImageUtil的generateThumbnail方法
package com.imooc.o2o.util;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import javax.imageio.ImageIO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import net.coobird.thumbnailator.Thumbnails;
import net.coobird.thumbnailator.geometry.Positions;
public class ImageUtil {
private static String basePath=Thread.currentThread().getContextClassLoader().getResource("").getPath();
private static final SimpleDateFormat sDateFormat=new SimpleDateFormat("yyyyMMddHHmmss");
private static final Random r=new Random();
private static Logger logger=LoggerFactory.getLogger(ImageUtil.class);
/**
* 将CommonsMultipartFile转化为file
* @param cFile
* @return
*/
public static File transferCommonsMultipartFileToFile(CommonsMultipartFile cFile) {
File newFile=new File(cFile.getOriginalFilename());
try {
cFile.transferTo(newFile);
} catch (IllegalStateException e) {
logger.error(e.toString());
e.printStackTrace();
} catch (IOException e) {
logger.error(e.toString());
e.printStackTrace();
}
return newFile;
}
/***
* 处理缩略图,并返回新生成图片的相对路径
* @param thumbnail
* @param targetAddr
* @return
*/
public static String generateThumbnail(File thumbnail,String targetAddr) {
String realFileName=getRandomFileName();
String extension=getFileExtension(thumbnail);
markDirPath(targetAddr);
String relativeAddr=targetAddr+realFileName+extension;
logger.debug("current relativeAddr is:"+relativeAddr);
File dest=new File(PathUtil.getImageBasePath()+relativeAddr);
logger.debug("current complete add is:"+PathUtil.getImageBasePath()+realFileName);
try {
Thumbnails.of(thumbnail).size(200, 200)
.watermark(Positions.BOTTOM_RIGHT,ImageIO.read(new File(basePath+"/watermark.jpg")), 0.25f)
.outputQuality(0.8f).toFile(dest);
} catch (Exception e) {
logger.error(e.toString());
e.printStackTrace();
}
return relativeAddr;
}
/**
* 创建目标路径涉及到的目录,即"home/eclipse/image/xxx.jpg
* 那么home eclipse image 这三个文件夹都得自动创建
* @param targetAddr
*/
private static void markDirPath(String targetAddr) {
String realFileParentPath=PathUtil.getImageBasePath()+targetAddr;
File dirPath=new File(realFileParentPath);
if(!dirPath.exists()) {
dirPath.mkdirs();
}
}
/**
* 获取输入文件流的扩展名
* @param thumbnail
* @return
*/
private static String getFileExtension(File cFile) {
String originalFileName=cFile.getName();
return originalFileName.substring(originalFileName.lastIndexOf("."));
}
/**
* 生成随机数文件名,当前年月日时分秒+五位随机数
* @return
*/
private static String getRandomFileName() {
// 获取随机的五位数
int rannum=r.nextInt(89999)+10000;
String nowTimeStr=sDateFormat.format(new Date());
return nowTimeStr+rannum;
}
public static void main(String[] args) throws IOException {
Thumbnails.of(new File("C:/Users/86187/Pictures/动图/5.jpg"))
.size(200,200).watermark(Positions.BOTTOM_RIGHT,ImageIO.read(new File(basePath+"/watermark.jpg")), 0.25f).
outputQuality(0.8f).toFile("C:/Users/86187/Pictures/动图/newfile.jpg");
}
}
3.字符串数组去重
List<String> strL1=new ArrayList<String>();
strL1.add("aaa");
strL1.add("bbbb");
strL1.add("ccc");
strL1.add("aaa");
System.out.println(strL1);
String[] strLNew=strL1.toArray(new String[0]);
Set set=new HashSet();
CollectionUtils.addAll(set,strLNew);
List<String> strL2=new ArrayList<String>(set);
System.out.println(strL2);
4.静态方法里面调用注入的实体类
//值的获取
PlanFileService planFileService =
(PlanFileService) AppServiceHelper.findBean("planFileServiceImpl");
package com.sgai.sadp.core.base.service;
import com.sgai.sadp.core.cache.CacheManager;
import com.sgai.sadp.core.exception.GlobalRuntimeException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.NoSuchMessageException;
import org.springframework.stereotype.Component;
@Component
public class AppServiceHelper implements ApplicationContextAware {
private static final Logger logger = LoggerFactory.getLogger(AppServiceHelper.class);
private static ApplicationContext applicationContext;
private static I18nMessage i18nMessage;
public AppServiceHelper() {
}
public static Object findBean(String beanId) throws NoSuchBeanDefinitionException {
Object service = applicationContext.getBean(beanId);
return service;
}
}
5.插入验证码
5.1 导入jar包
<!-- 验证码 -->
<dependency>
<groupId>com.github.penggle</groupId>
<artifactId>kaptcha</artifactId>
<version>2.3.2</version>
</dependency>
5.2 配置web.xml文件
<servlet>
<servlet-name>Kaptcha</servlet-name>
<servlet-class>com.google.code.kaptcha.servlet.KaptchaServlet</servlet-class>
<!-- 是否有边框 -->
<init-param>
<param-name>kaptcha.border</param-name>
<param-value>no</param-value>
</init-param>
<!-- 字体颜色 -->
<init-param>
<param-name>kaptcha.textproducer.font.color</param-name>
<param-value>red</param-value>
</init-param>
<!-- 图片宽度 -->
<init-param>
<param-name>kaptcha.image.width</param-name>
<param-value>135</param-value>
</init-param>
<!-- 使用那些字符生成验证码 -->
<init-param>
<param-name>kaptcha.textproducer.char.string</param-name>
<param-value>ABCDEFGKLP36592</param-value>
</init-param>
<!-- 图片高度 -->
<init-param>
<param-name>kaptcha.image.height</param-name>
<param-value>50</param-value>
</init-param>
<!-- 字体大小 -->
<init-param>
<param-name>kaptcha.textproducer.font.size</param-name>
<param-value>43</param-value>
</init-param>
<!-- 干扰线的颜色 -->
<init-param>
<param-name>kaptcha.noise.color</param-name>
<param-value>black</param-value>
</init-param>
<!-- 字符个数 -->
<init-param>
<param-name>kaptcha.textproducer.char.length</param-name>
<param-value>4</param-value>
</init-param>
<!-- 字体 -->
<init-param>
<param-name>kaptcha.textproducer.font.names</param-name>
<param-value>Arial</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Kaptcha</servlet-name>
<url-pattern>/Kaptcha</url-pattern>
</servlet-mapping>
5.3 html文件的更改
<li>
<div class="item-content">
<div class="item-inner">
<div class="item-title label">验证码</div>
<input type="text" id="j_captcha" placeholder="验证码">
<div class="item-input">
<img id="captcha_img" alt="点击更换" title="点击更换"
onclick="changeVerifyCode(this)" src="../Kaptcha" />
</div>
</div>
</div>
</li>
5.4点击更换验证码事件
function changeVerifyCode(img) {
img.src = "../Kaptcha?" + Math.floor(Math.random() * 100);
}
6.枚举类型的使用
1.创建枚举类
package com.sgai.sadp.supplier.cgSupplierTpgpe50.service;
import com.sgai.sadp.supplier.cgSupplierTpgpe50.service.impl.gnk.GongYingLiangAutomaticHandler;
import com.sgai.sadp.supplier.cgSupplierTpgpe50.service.impl.gnk.TiePinWeiAutomaticHandler;
import com.sgai.sadp.supplier.cgSupplierTpgpe50.service.impl.mt.HuiFenAutomaticHandler;
import com.sgai.sadp.supplier.cgSupplierTpgpe50.service.impl.mt.LiuFenAutomaticHandler;
import com.sgai.sadp.supplier.cgSupplierTpgpe50.service.impl.mt.ShuiFenAutomaticHandler;
import com.sgai.sadp.supplier.cgSupplierTpgpe50.service.impl.zcbj.*;
public enum AutomaticTypeEnum {
FORMULA01("FORMULA01", new GongYingLiangAutomaticHandler()),
FORMULA02("FORMULA02", new TiePinWeiAutomaticHandler()),
FORMULA03("FORMULA03", new com.sgai.sadp.supplier.cgSupplierTpgpe50.service.impl.mt.GongYingLiangAutomaticHandler()),
FORMULA04("FORMULA04", new ShuiFenAutomaticHandler()),
FORMULA05("FORMULA05", new HuiFenAutomaticHandler()),
FORMULA06("FORMULA06", new LiuFenAutomaticHandler()),
FORMULA07("FORMULA07", new JiaoHuoLvAutomaticHandler()),
FORMULA08("FORMULA08", new WeiJiaoHuoXiangAutomaticHandler()),
FORMULA09("FORMULA09", new JiaGeShuiPingAutomaticHandler()),
FORMULA10("FORMULA10", new JiaGeJingZhengXingAutomaticHandler()),
FORMULA11("FORMULA11", new ZhongBiaoHouQiBiaoAutomaticHandler()),
FORMULA12("FORMULA12", new HeTongJinEAutomaticHandler());
private final String automaticType;
private final BaseAutomaticHandler automaticHandler;
AutomaticTypeEnum(String automaticType, BaseAutomaticHandler automaticHandler) {
this.automaticType = automaticType;
this.automaticHandler = automaticHandler;
}
/**
* 匹配
*/
public static AutomaticTypeEnum match(String automaticType) {
AutomaticTypeEnum[] values = AutomaticTypeEnum.values();
for (AutomaticTypeEnum typeEnum : values) {
if (typeEnum.automaticType.equals(automaticType)) {
return typeEnum;
}
}
return null;
}
public String getAutomaticType() {
return automaticType;
}
public BaseAutomaticHandler getAutomaticHandler() {
return automaticHandler;
}
}
2.创建枚举实体类
1.GongYingLiangAutomaticHandler
package com.sgai.sadp.supplier.cgSupplierTpgpe50.service.impl.gnk;
import com.sgai.sadp.order.mapper.OrderInfo02Mapper;
import com.sgai.sadp.storage.cgInstorageMetering.mapper.CgInstorageMeteringMapper;
import com.sgai.sadp.supplier.cgSupplierTpgpe01.entity.CgSupplierTpgpe01;
import com.sgai.sadp.supplier.cgSupplierTpgpe50.entity.CgSupplierTpgpe50;
import com.sgai.sadp.supplier.cgSupplierTpgpe50.service.BaseAutomaticHandler;
import org.springframework.beans.factory.annotation.Autowired;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class GongYingLiangAutomaticHandler extends BaseAutomaticHandler {
@Autowired
private CgInstorageMeteringMapper cgInstorageMeteringMapper;
@Autowired
private OrderInfo02Mapper orderInfo02Mapper;
@Override
public Double automatic(CgSupplierTpgpe50 cgSupplierTpgpe50, CgSupplierTpgpe01 cgSupplierTpgpe01 ) {
String peClassId=cgSupplierTpgpe50.getPeClassId();
String matAccType="42";
List<String> supplierIds=new ArrayList<>();
List<String> itemIds=new ArrayList<>();
List<String> spManageTypes=new ArrayList<>();
supplierIds.add(cgSupplierTpgpe50.getSupplierId());//供应商
String startDate=cgSupplierTpgpe01.getStartDate();//打分开始时间
String endDate=cgSupplierTpgpe01.getEndDate();//打分结算时间
itemIds.add(cgSupplierTpgpe50.getPeIgrpId());//获取物料相关数据
spManageTypes.add(cgSupplierTpgpe50.getPeMgrpId());//获取管理类别相关数据
Double automaticValue=0d;
BigDecimal quantityValue=new BigDecimal(0);//数量的值
if("EC00002".equals(peClassId)){//国内矿
matAccType="42";
//计算数量
//供应量的值
BigDecimal supplyValue=this.insMetSumWeight(matAccType,supplierIds,startDate,endDate,itemIds,spManageTypes);
//计划量的值
BigDecimal planValue=this.sumOrderQty(matAccType,supplierIds,startDate,endDate,itemIds,spManageTypes);
quantityValue=supplyValue.divide(planValue).multiply(new BigDecimal(0.25));
}
automaticValue=quantityValue.doubleValue();
return automaticValue;
}
/**
* 查询数量里面供应量,取值来源于入库表中的计量信息
* @param matAccType 物料核算类型
* @param supplierIds 供应商记录集合
* @param startDate 开始时间
* @param endDate 结束时间
* @param itemIds 物料
* @param spManageTypes 管理类别
* @return
*/
private BigDecimal insMetSumWeight(String matAccType, List<String> supplierIds, String startDate,String endDate,List<String> itemIds,List<String> spManageTypes){
Map<String,Object> map=new HashMap<>();
map.put("matAccType",matAccType);
map.put("supplierIds",supplierIds);
map.put("startDate",startDate);
map.put("endDate",endDate);
map.put("itemIds",itemIds);
map.put("spManageTypes",spManageTypes);
return cgInstorageMeteringMapper.insMetSumWeight(map);
}
/**
* 查询数量里面计划量,取值来源于订单表中的数据
* @param matAccType 物料核算类型
* @param supplierIds 供应商记录集合
* @param startDate 开始时间
* @param endDate 结束时间
* @return
*/
private BigDecimal sumOrderQty(String matAccType, List<String> supplierIds, String startDate,String endDate,List<String> itemIds,List<String> spManageTypes){
Map<String,Object> map=new HashMap<>();
map.put("matAccType",matAccType);
map.put("supplierIds",supplierIds);
map.put("startDate",startDate);
map.put("endDate",endDate);
map.put("itemIds",itemIds);
map.put("spManageTypes",spManageTypes);
return orderInfo02Mapper.sumOrderQty(map);
}
}
2.TiePinWeiAutomaticHandler
package com.sgai.sadp.supplier.cgSupplierTpgpe50.service.impl.gnk;
import com.sgai.sadp.supplier.cgSupplierTpgpe01.entity.CgSupplierTpgpe01;
import com.sgai.sadp.supplier.cgSupplierTpgpe50.entity.CgSupplierTpgpe50;
import com.sgai.sadp.supplier.cgSupplierTpgpe50.service.BaseAutomaticHandler;
public class TiePinWeiAutomaticHandler extends BaseAutomaticHandler {
@Override
public Double automatic(CgSupplierTpgpe50 cgSupplierTpgpe50, CgSupplierTpgpe01 cgSupplierTpgpe01) {
cgSupplierTpgpe50.getPeLevelScore();
return 2d;
}
}
3.GongYingLiangAutomaticHandler
package com.sgai.sadp.supplier.cgSupplierTpgpe50.service.impl.mt;
import com.sgai.sadp.supplier.cgSupplierTpgpe01.entity.CgSupplierTpgpe01;
import com.sgai.sadp.supplier.cgSupplierTpgpe50.entity.CgSupplierTpgpe50;
import com.sgai.sadp.supplier.cgSupplierTpgpe50.service.BaseAutomaticHandler;
public class GongYingLiangAutomaticHandler extends BaseAutomaticHandler {
@Override
public Double automatic(CgSupplierTpgpe50 cgSupplierTpgpe50, CgSupplierTpgpe01 cgSupplierTpgpe01) {
return 2d;
}
}
4.ShuiFenAutomaticHandler
package com.sgai.sadp.supplier.cgSupplierTpgpe50.service.impl.mt;
import com.sgai.sadp.supplier.cgSupplierTpgpe01.entity.CgSupplierTpgpe01;
import com.sgai.sadp.supplier.cgSupplierTpgpe50.entity.CgSupplierTpgpe50;
import com.sgai.sadp.supplier.cgSupplierTpgpe50.service.BaseAutomaticHandler;
public class GongYingLiangAutomaticHandler extends BaseAutomaticHandler {
@Override
public Double automatic(CgSupplierTpgpe50 cgSupplierTpgpe50, CgSupplierTpgpe01 cgSupplierTpgpe01) {
return 2d;
}
}
5.HuiFenAutomaticHandler
package com.sgai.sadp.supplier.cgSupplierTpgpe50.service.impl.mt;
import com.sgai.sadp.supplier.cgSupplierTpgpe01.entity.CgSupplierTpgpe01;
import com.sgai.sadp.supplier.cgSupplierTpgpe50.entity.CgSupplierTpgpe50;
import com.sgai.sadp.supplier.cgSupplierTpgpe50.service.BaseAutomaticHandler;
public class HuiFenAutomaticHandler extends BaseAutomaticHandler {
@Override
public Double automatic(CgSupplierTpgpe50 cgSupplierTpgpe50, CgSupplierTpgpe01 cgSupplierTpgpe01) {
return 2d;
}
}
6.LiuFenAutomaticHandler
package com.sgai.sadp.supplier.cgSupplierTpgpe50.service.impl.mt;
import com.sgai.sadp.supplier.cgSupplierTpgpe01.entity.CgSupplierTpgpe01;
import com.sgai.sadp.supplier.cgSupplierTpgpe50.entity.CgSupplierTpgpe50;
import com.sgai.sadp.supplier.cgSupplierTpgpe50.service.BaseAutomaticHandler;
public class LiuFenAutomaticHandler extends BaseAutomaticHandler {
@Override
public Double automatic(CgSupplierTpgpe50 cgSupplierTpgpe50, CgSupplierTpgpe01 cgSupplierTpgpe01) {
return 2d;
}
}
7.JiaoHuoLvAutomaticHandler
package com.sgai.sadp.supplier.cgSupplierTpgpe50.service.impl.zcbj;
import com.sgai.sadp.base.cgBaseFunctionLimit.service.CgBaseFunctionLimitService;
import com.sgai.sadp.core.base.service.AppServiceHelper;
import com.sgai.sadp.storage.mapper.StorageReceiveGoodsMapper;
import com.sgai.sadp.supplier.cgSupplierTpgpe01.entity.CgSupplierTpgpe01;
import com.sgai.sadp.supplier.cgSupplierTpgpe50.entity.CgSupplierTpgpe50;
import com.sgai.sadp.supplier.cgSupplierTpgpe50.service.BaseAutomaticHandler;
import org.springframework.beans.factory.annotation.Autowired;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
public class JiaoHuoLvAutomaticHandler extends BaseAutomaticHandler {
@Override
public Double automatic(CgSupplierTpgpe50 cgSupplierTpgpe50, CgSupplierTpgpe01 cgSupplierTpgpe01) {
StorageReceiveGoodsMapper storageReceiveGoodsMapper = (StorageReceiveGoodsMapper) AppServiceHelper.findBean("storageReceiveGoodsMapper");
List<HashMap> jiaoHuoLv = storageReceiveGoodsMapper.findJiaoHuoLv(new HashMap() {{
put("startDate",cgSupplierTpgpe01.getStartDate());
put("endDate",cgSupplierTpgpe01.getEndDate());
put("supplierId",cgSupplierTpgpe50.getSupplierId());
put("iOrMgrp",cgSupplierTpgpe50.getPeMgrpId());
}});
List<HashMap> collect = jiaoHuoLv.stream().filter(item -> {
return Long.valueOf(((String)item.get("receiveDate")).substring(0,8))<=Long.valueOf((String)item.get("deliveryTime"));
}).collect(Collectors.toList());
BigDecimal lvB = new BigDecimal(collect.size()).divide(new BigDecimal(jiaoHuoLv.size())).setScale(4,BigDecimal.ROUND_HALF_UP);
double lv = lvB.doubleValue();
if(lv<1&&lv>=0.95){
return new BigDecimal(cgSupplierTpgpe50.getPeLevelScore()).multiply(new BigDecimal(0.9)).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
}else if(lv<0.95&&lv>=0.9){
return new BigDecimal(cgSupplierTpgpe50.getPeLevelScore()).multiply(new BigDecimal(0.8)).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
}else if(lv<0.9){
return 0d;
}
return cgSupplierTpgpe50.getPeLevelScore();
}
}
8.WeiJiaoHuoXiangAutomaticHandler
package com.sgai.sadp.supplier.cgSupplierTpgpe50.service.impl.zcbj;
import com.sgai.sadp.core.base.service.AppServiceHelper;
import com.sgai.sadp.storage.mapper.StorageReceiveGoodsMapper;
import com.sgai.sadp.supplier.cgSupplierTpgpe01.entity.CgSupplierTpgpe01;
import com.sgai.sadp.supplier.cgSupplierTpgpe50.entity.CgSupplierTpgpe50;
import com.sgai.sadp.supplier.cgSupplierTpgpe50.service.BaseAutomaticHandler;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
public class WeiJiaoHuoXiangAutomaticHandler extends BaseAutomaticHandler {
@Override
public Double automatic(CgSupplierTpgpe50 cgSupplierTpgpe50, CgSupplierTpgpe01 cgSupplierTpgpe01) {
StorageReceiveGoodsMapper storageReceiveGoodsMapper = (StorageReceiveGoodsMapper) AppServiceHelper.findBean("storageReceiveGoodsMapper");
List<HashMap> jiaoHuoLv = storageReceiveGoodsMapper.findJiaoHuoLv(new HashMap() {{
put("startDate",cgSupplierTpgpe01.getStartDate());
put("endDate",cgSupplierTpgpe01.getEndDate());
put("supplierId",cgSupplierTpgpe50.getSupplierId());
put("iOrMgrp",cgSupplierTpgpe50.getPeMgrpId());
}});
//未准时交货项
List<HashMap> collect = jiaoHuoLv.stream().filter(item -> {
return Long.valueOf(((String)item.get("receiveDate")).substring(0,8))>Long.valueOf((String)item.get("deliveryTime"));
}).collect(Collectors.toList());
int cou = collect.size();
if(cou>=1&&cou<=3){
return new BigDecimal(cgSupplierTpgpe50.getPeLevelScore()).multiply(new BigDecimal(0.9)).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
}else if(cou>=4&&cou<=6){
return new BigDecimal(cgSupplierTpgpe50.getPeLevelScore()).multiply(new BigDecimal(0.8)).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
}else if(cou>=7&&cou<=10){
return new BigDecimal(cgSupplierTpgpe50.getPeLevelScore()).multiply(new BigDecimal(0.5)).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
}else if(cou>10){
return 0d;
}
return cgSupplierTpgpe50.getPeLevelScore();
}
}
9.JiaGeShuiPingAutomaticHandler
package com.sgai.sadp.supplier.cgSupplierTpgpe50.service.impl.zcbj;
import com.sgai.sadp.supplier.cgSupplierTpgpe01.entity.CgSupplierTpgpe01;
import com.sgai.sadp.supplier.cgSupplierTpgpe50.entity.CgSupplierTpgpe50;
import com.sgai.sadp.supplier.cgSupplierTpgpe50.service.BaseAutomaticHandler;
public class JiaGeShuiPingAutomaticHandler extends BaseAutomaticHandler {
@Override
public Double automatic(CgSupplierTpgpe50 cgSupplierTpgpe50, CgSupplierTpgpe01 cgSupplierTpgpe01) {
return 2d;
}
}
10.JiaGeJingZhengXingAutomaticHandler
package com.sgai.sadp.supplier.cgSupplierTpgpe50.service.impl.zcbj;
import com.sgai.sadp.supplier.cgSupplierTpgpe01.entity.CgSupplierTpgpe01;
import com.sgai.sadp.supplier.cgSupplierTpgpe50.entity.CgSupplierTpgpe50;
import com.sgai.sadp.supplier.cgSupplierTpgpe50.service.BaseAutomaticHandler;
public class ZhongBiaoHouQiBiaoAutomaticHandler extends BaseAutomaticHandler {
@Override
public Double automatic(CgSupplierTpgpe50 cgSupplierTpgpe50, CgSupplierTpgpe01 cgSupplierTpgpe01) {
return 2d;
}
}
11.ZhongBiaoHouQiBiaoAutomaticHandler
package com.sgai.sadp.supplier.cgSupplierTpgpe50.service.impl.zcbj;
import com.sgai.sadp.supplier.cgSupplierTpgpe01.entity.CgSupplierTpgpe01;
import com.sgai.sadp.supplier.cgSupplierTpgpe50.entity.CgSupplierTpgpe50;
import com.sgai.sadp.supplier.cgSupplierTpgpe50.service.BaseAutomaticHandler;
public class ZhongBiaoHouQiBiaoAutomaticHandler extends BaseAutomaticHandler {
@Override
public Double automatic(CgSupplierTpgpe50 cgSupplierTpgpe50, CgSupplierTpgpe01 cgSupplierTpgpe01) {
return 2d;
}
}
12.HeTongJinEAutomaticHandler
package com.sgai.sadp.supplier.cgSupplierTpgpe50.service.impl.zcbj;
import com.sgai.sadp.supplier.cgSupplierTpgpe01.entity.CgSupplierTpgpe01;
import com.sgai.sadp.supplier.cgSupplierTpgpe50.entity.CgSupplierTpgpe50;
import com.sgai.sadp.supplier.cgSupplierTpgpe50.service.BaseAutomaticHandler;
public class HeTongJinEAutomaticHandler extends BaseAutomaticHandler {
@Override
public Double automatic(CgSupplierTpgpe50 cgSupplierTpgpe50, CgSupplierTpgpe01 cgSupplierTpgpe01) {
return 2d;
}
}
3.使用枚举对象
AutomaticTypeEnum automaticTypeEnum = AutomaticTypeEnum.match(cgSupplierTpgpe50.getTenantId());
3.获取配置文件数据
public static String getVHost() {
try {
if(null==CW_VHOST){
InputStream stream = ContantsSys.class.getClassLoader().getResourceAsStream("AppPropertiesConfig.properties");
Properties props = new Properties();
props.load(stream);
CW_VHOST = props.getProperty("cw.mq.vhost");
}
} catch (IOException e) {
e.printStackTrace();
}
return CW_VHOST;
}