| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999 |
- package cn.com.goldenwater.dcproj.service.impl.ducha;
- import cn.com.goldenwater.core.service.AbstractCrudService;
- import cn.com.goldenwater.dcproj.constValue.AdCodeLabel;
- import cn.com.goldenwater.dcproj.constValue.CommonLabel;
- import cn.com.goldenwater.dcproj.dao.*;
- import cn.com.goldenwater.dcproj.dto.*;
- import cn.com.goldenwater.dcproj.enums.SystemFlagEnum;
- import cn.com.goldenwater.dcproj.model.*;
- import cn.com.goldenwater.dcproj.param.*;
- import cn.com.goldenwater.dcproj.service.*;
- import cn.com.goldenwater.dcproj.util.CheckUtil;
- import cn.com.goldenwater.dcproj.util.StatisticalUtil;
- import cn.com.goldenwater.dcproj.utils.*;
- import cn.com.goldenwater.id.util.UuidUtil;
- import cn.com.goldenwater.target.CheckException;
- import cn.com.goldenwater.util.common.IPUtils;
- import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
- import com.github.pagehelper.PageHelper;
- import com.github.pagehelper.PageInfo;
- import net.sf.json.JSONObject;
- import org.apache.commons.collections.MapUtils;
- import org.apache.commons.lang3.StringUtils;
- import org.apache.cxf.endpoint.Client;
- import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.data.redis.core.RedisTemplate;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.util.Assert;
- import javax.imageio.ImageIO;
- import javax.servlet.http.HttpServletRequest;
- import java.awt.*;
- import java.awt.font.FontRenderContext;
- import java.awt.geom.Rectangle2D;
- import java.awt.image.BufferedImage;
- import java.io.File;
- import java.net.InetAddress;
- import java.net.UnknownHostException;
- import java.util.List;
- import java.util.*;
- import java.util.concurrent.TimeUnit;
- /**
- * @author zhaohg
- * @date 2019-2-23
- */
- @Service
- @Transactional
- public class BisInspAllRlationPersServiceImpl extends AbstractCrudService<BisInspAllRlationPers, BisInspAllRlationPersParam> implements BisInspAllRlationPersService {
- @Autowired
- private BisInspAllRlationPersDao bisInspAllRlationPersDao;
- @Autowired
- private UserRoleDao userRoleDao;
- @Autowired
- private BisInspPersOrgService bisInspPersOrgService;
- @Autowired
- private SupervisionPlanDao supervisionPlanDao;
- @Autowired
- private OlBisInspOrgDao olBisInspOrgDao;
- @Autowired
- private RedisTemplate redisTemplate;
- @Value("${btMessageServiceUrl}")
- public String btMessageServiceUrl;
- @Autowired
- public PersPositionLatestDao persPositionLatestDao;
- @Autowired
- private BisInspPlanDpService bisInspPlanDpService;
- @Autowired
- private BisInspAllService bisInspAllService;
- public BisInspAllRlationPersServiceImpl(BisInspAllRlationPersDao bisInspAllRlationPersDao) {
- super(bisInspAllRlationPersDao);
- this.bisInspAllRlationPersDao = bisInspAllRlationPersDao;
- }
- private static String apiKey = "1036432406699048960";
- //
- private static String apiSecrect = "bbSsX1wvmaKdca5x2+yBDgeFtl9hj4zJmnegunWuLuHLwLo+QjxOr3//P4BJNrVADa7tN4w0DX1KS/VSec5G0x+ucDeAcSt9tWgFGyoBVtblybh+vzLbwH4sJa92hQfu\n";
- private Logger logger = LoggerFactory.getLogger(getClass());
- @Autowired
- private DdMessageDao ddMessageDao;
- @Value("${api.url}")
- private String apiUrl;
- @Value("${sms.template}")
- private String smsTemplate;
- @Value("${sms.bak.template}")
- private String bakTemplate;
- @Value("${work.url}")
- private String workUrl;
- @Value("${sms.mwr.aliyun}")
- private String smsMwrAliyun;
- @Override
- public BisInspAllRlationPers createUser(BisInspAllRlationPers bisInspAllRlationPers) {
- CheckUtil.notEmpty(bisInspAllRlationPers.getPersName(), "人员姓名为必填参数");
- if (StringUtils.isBlank(bisInspAllRlationPers.getOwnerSystem())) {
- bisInspAllRlationPers.setOwnerSystem("DC_ALL");
- }
- bisInspAllRlationPers.setGuid(UuidUtil.uuid());
- BisInspAllRlationPersParam param = new BisInspAllRlationPersParam();
- param.setMobilenumb(bisInspAllRlationPers.getMobilenumb());
- List list = findList(param);
- if (list != null && list.size() > 0) {
- throw new CheckException("用户不能重复添加");
- }
- addPreOrg(bisInspAllRlationPers);
- //密码MD5加密
- if (StringUtils.isNotBlank(bisInspAllRlationPers.getPwd())) {
- bisInspAllRlationPers.setPwd(MD5.getMD5(aesUtil.desEncrypt(bisInspAllRlationPers.getPwd().replace(" ", "+"))));
- }
- insert(bisInspAllRlationPers);
- //添加人员到小鱼账号
- return bisInspAllRlationPers;
- }
- private void addPreOrg(BisInspAllRlationPers bisInspAllRlationPers) {
- //先删除授权,再添加机构授权
- BisInspPersOrgParam persOrgParam = new BisInspPersOrgParam();
- persOrgParam.setPersId(bisInspAllRlationPers.getGuid());
- persOrgService.deleteBy(persOrgParam);
- if (StringUtils.isNotBlank(bisInspAllRlationPers.getOrgId())) {
- OlBisInspOrg olBisInspOrg = olBisInspOrgDao.get(bisInspAllRlationPers.getOrgId());
- if (olBisInspOrg != null) {
- bisInspAllRlationPers.setOrgNm(olBisInspOrg.getOrgNm());
- bisInspAllRlationPers.setProvince(olBisInspOrg.getAdCode());
- }
- BisInspPersOrg inspPersOrg = new BisInspPersOrg();
- inspPersOrg.setOrgId(bisInspAllRlationPers.getOrgId());
- inspPersOrg.setPersId(bisInspAllRlationPers.getGuid());
- if (StringUtils.isNotBlank(bisInspAllRlationPers.getPersType())) {
- inspPersOrg.setUserType(bisInspAllRlationPers.getPersType());
- } else {
- inspPersOrg.setUserType(AdCodeLabel.GROUP_LEADER);
- }
- BisInspPersOrgParam bisInspPersOrgParam = new BisInspPersOrgParam();
- bisInspPersOrgParam.setPersId(inspPersOrg.getPersId());
- bisInspPersOrgParam.setOrgId(inspPersOrg.getOrgId());
- if (null == persOrgService.getBy(bisInspPersOrgParam)) {
- persOrgService.insert(inspPersOrg);
- }
- }
- }
- @Override
- public boolean sendMessage(String phone) throws Exception {
- BisInspAllRlationPersParam param = new BisInspAllRlationPersParam();
- param.setMobilenumb(phone);
- BisInspAllRlationPers pers = bisInspAllRlationPersDao.getBy(param);
- if (null != pers && StringUtils.isNotBlank(pers.getGuid())) {
- String key = "sms:" + phone;
- Object value = redisTemplate.opsForValue().get(key);
- if (value == null) {
- value = 1;
- }
- Integer intValue = Integer.valueOf(String.valueOf(value));
- String smsTemp = smsTemplate;
- if (intValue.intValue() >= 5) {
- smsTemp = bakTemplate;
- }
- Map<String, String> params = new HashMap<String, String>();
- Random rand = new Random();
- int num = rand.nextInt(900000) + 100000;
- String code = num + "";
- params.put("apiKey", apiKey);
- params.put("apiSecrect", apiSecrect);
- params.put("templateParam", "{\"code\":\"" + code + "\"}");
- params.put("signName", "金水云平台");
- params.put("templeteCode", smsTemp);//SMS_158547721
- params.put("mobile", phone);
- System.out.println("发送短信前:" + phone);
- logger.info("发送短信前:" + phone);
- SendSmsResponse sendSmsResponse = null;
- try {
- String content = "";
- if ("0".equals(smsMwrAliyun)) {
- sendSmsResponse = SmsUtil.send(params.get("mobile"), params.get("templateParam"), params.get("apiSecrect"), params.get("templeteCode"), params.get("signName"));
- content = sendSmsResponse.getMessage();
- System.out.println("发送短信后:" + content);
- logger.info("发送短信后:" + content);
- }
- if ("1".equals(smsMwrAliyun)) {
- content = HttpClientUtils.doHttpsPost2(apiUrl + "/sms/send", params, new HashMap<>());
- //互联网短信平台 或者 106短信
- System.out.println("发送短信后:" + content);
- logger.info("发送短信后:" + content);
- } else if ("2".equals(smsMwrAliyun)) {//调用新疆兵团短信服务
- content = sendMsgByBtMessgaeService(phone, "本次登录水利监管工作平台验证码为:" + code + ",有效时间5分钟!");
- System.out.println("发送短信后:" + content);
- logger.info("发送短信后:" + content);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- DdMessage ddMessage = new DdMessage();
- ddMessage.setId(UuidUtil.uuid());
- ddMessage.setPhone(phone);
- ddMessage.setCode(code);
- ddMessage.setAccessTime(new Date());
- ddMessageDao.insert(ddMessage);
- Object keyValue = redisTemplate.opsForValue().get(key);
- if (keyValue == null) {
- redisTemplate.boundValueOps(key).increment(1);
- redisTemplate.boundValueOps(key).expire(1, TimeUnit.HOURS);
- } else {
- redisTemplate.boundValueOps(key).increment(1);
- }
- return true;
- }
- return false;
- }
- public String sendMsgByBtMessgaeService(String phone, String content) {
- JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
- Client client = dcf.createClient(btMessageServiceUrl);
- Object[] objects;
- try {
- objects = client.invoke("sendSms", "sjjggzpt", phone, content);
- return objects[0].toString();
- } catch (java.lang.Exception e) {
- e.printStackTrace();
- }
- return "";
- }
- @Override
- public BisInspAllRlationPers loginByCode(String phone, String code) {
- DdMessageParam ddMessageParam = new DdMessageParam();
- ddMessageParam.setPhone(phone);
- ddMessageParam.setCode(code);
- // 查看是否有对应的 手机-短信验证码
- List<DdMessage> list = ddMessageDao.findList(ddMessageParam);
- if (null != list && list.size() > 0) {
- DdMessage message = list.get(0);
- BisInspAllRlationPersParam param = new BisInspAllRlationPersParam();
- param.setMobilenumb(phone);
- // 获取用户信息
- BisInspAllRlationPers pers = bisInspAllRlationPersDao.getBy(param);
- // 时间判断-超过未超过六分钟,则返回用户信息
- if (null != pers && StringUtils.isNotBlank(pers.getGuid())
- && null != message && StringUtils.isNotBlank(message.getId())) {
- long access = message.getAccessTime().getTime();
- long now = System.currentTimeMillis();
- long nm = 1000 * 60 * 10;
- if (nm > now - access) {
- pers.setPwd(null);
- return getOne(pers.getGuid());
- }
- }
- }
- return null;
- }
- @Override
- public boolean createWork() {
- boolean bol = true;
- try {
- PinYin pin = new PinYin();
- String backgroundPath1 = "";
- String qrCodePath1 = "";
- List<BisInspAllRlationPers> list = bisInspAllRlationPersDao.getZjList();
- for (BisInspAllRlationPers per : list) {
- String persId = per.getGuid();
- String cName = per.getPersName();
- cName = cName.trim();
- String eName = pin.getPingYin(cName);
- eName = eName.trim();
- String orgName = per.getOrgNm();
- orgName = orgName.trim();
- String admDuty = per.getAdmDuty();
- admDuty = admDuty.trim();
- String dpPost = per.getDppost();
- dpPost = dpPost.trim();
- String duty = "";
- if (!"".equals(admDuty) && !"/".equals(admDuty)) {
- duty = admDuty;
- if (!"".equals(dpPost) && !"/".equals(dpPost)) {
- duty += "/" + dpPost;
- }
- } else {
- if (!"".equals(dpPost) && !"/".equals(dpPost)) {
- duty = dpPost;
- }
- }
- System.out.println(cName + "--制作开始");
- String idNm = per.getIdnm();
- String outPutPath = "D:\\image\\ryzj\\" + orgName + "\\" + cName + "-竖版正面.jpg";
- QRCodeUtil.encode(workUrl + "/sldc/work.html?pserId=" + persId, "D:\\image\\logo\\logo.png", "D:\\image\\ewm\\" + orgName, cName, true);
- qrCodePath1 = "D:\\image\\ewm\\" + orgName + "\\" + cName + ".jpg";
- String yrCodePath = getFiles("D:\\image\\ryimage", cName);
- backgroundPath1 = "D:\\image\\0001.jpg";
- overlapImage(backgroundPath1, qrCodePath1, yrCodePath, cName.trim(), eName.trim(), orgName.trim(), duty.trim(), idNm.trim(), outPutPath);
- String backgroundPath2 = "D:\\image\\0002.jpg";
- String outPutPath2 = "D:\\image\\ryzj\\" + orgName + "\\" + cName + "-竖版背面.jpg";
- overlapImage1(backgroundPath2, qrCodePath1, outPutPath2);
- backgroundPath1 = "D:\\image\\0003.jpg";
- outPutPath2 = "D:\\image\\ryzj\\" + orgName + "\\" + cName + "-横版正面.jpg";
- overlapImage2(backgroundPath1, qrCodePath1, yrCodePath, cName.trim(), eName.trim(), orgName.trim(), duty.trim(), idNm.trim(), outPutPath2);
- backgroundPath2 = "D:\\image\\0004.jpg";
- outPutPath2 = "D:\\image\\ryzj\\" + orgName + "\\" + cName + "-横版背面.jpg";
- overlapImage3(backgroundPath2, qrCodePath1, outPutPath2);
- System.out.println(cName + "--制作结束");
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return bol;
- }
- @Override
- public int setHeadMan(BisInspAllRlation bisInspAllRlation) {
- return this.bisInspAllRlationPersDao.setHeadMan(bisInspAllRlation);
- }
- public String overlapImage(String backgroundPath, String qrCodePath, String yrCodePath, String cName, String eName, String orgName, String duty, String idNm, String outPutPath) {
- try {
- //设置图片大小
- BufferedImage background = resizeImage(898, 1252, ImageIO.read(new File(backgroundPath)));
- BufferedImage qrCode = resizeImage(170, 170, ImageIO.read(new File(qrCodePath)));
- BufferedImage yrCode = resizeImage(300, 411, ImageIO.read(new File(yrCodePath)));
- //在背景图片中添加入需要写入的信息,例如:扫描下方二维码,欢迎大家添加我的淘宝返利机器人,居家必备,省钱购物专属小秘书!
- //String message = "扫描下方二维码,欢迎大家添加我的淘宝返利机器人,居家必备,省钱购物专属小秘书!";
- FontRenderContext frc = new FontRenderContext(null, true, true);
- Font font = new Font("微软雅黑", Font.BOLD, 40);
- Rectangle2D r2D = font.getStringBounds(cName, frc);
- int rWidth = (int) Math.round(r2D.getWidth());
- int rX = (int) Math.round(r2D.getX());
- Rectangle r = new Rectangle(0, 0, 901, 1240);
- int a = (r.width / 2) - (rWidth / 2) - rX;
- Graphics2D g = background.createGraphics();
- g.setColor(Color.BLACK);
- g.setFont(font);
- g.drawString(cName, r.x + a, 770);
- FontRenderContext frc1 = new FontRenderContext(null, true, true);
- Font font1 = new Font("Arial", Font.BOLD, 40);
- Rectangle2D r2D1 = font1.getStringBounds(eName, frc1);
- int rWidth1 = (int) Math.round(r2D1.getWidth());
- int rX1 = (int) Math.round(r2D1.getX());
- Rectangle r1 = new Rectangle(0, 0, 901, 1210);
- int a1 = (r1.width / 2) - (rWidth1 / 2) - rX1;
- g.setFont(font1);
- g.drawString(eName, r1.x + a1, 817);
- g.setFont(getFont(orgName, "宋体", 28));
- g.drawString(orgName, 317, 895);
- g.setFont(getFont(duty, "宋体", 28));
- g.drawString(duty, 317, 957);
- g.setFont(getFont(idNm, "Arial", 28));
- g.drawString(idNm, 317, 1023);
- //在背景图片上添加二维码图片
- g.drawImage(qrCode, 655, 862, qrCode.getWidth(), qrCode.getHeight(), null);
- g.drawImage(yrCode, 296, 300, yrCode.getWidth(), yrCode.getHeight(), null);
- g.dispose();
- QRCodeUtil.mkdirs(outPutPath);
- ImageIO.write(background, "jpg", new File(outPutPath));
- File outPutPath_file = new File(outPutPath);
- // DpiHandleHelper.handleDpi(outPutPath_file,300,300);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
- public Font getFont(String val, String fontStr, int fontSize) {
- FontRenderContext frc = new FontRenderContext(null, true, true);
- Font font = new Font(fontStr, Font.BOLD, fontSize);
- Rectangle2D r2D = font.getStringBounds(val, frc);
- int w = (int) Math.round(r2D.getWidth());
- int iw = 276;
- while (w > iw) {
- font = new Font(fontStr, Font.BOLD, fontSize--);
- r2D = font.getStringBounds(val, frc);
- w = (int) Math.round(r2D.getWidth());
- }
- return font;
- }
- public String overlapImage1(String backgroundPath, String qrCodePath, String outPutPath) {
- try {
- //设置图片大小
- BufferedImage background = resizeImage(898, 1252, ImageIO.read(new File(backgroundPath)));
- BufferedImage qrCode = resizeImage(250, 250, ImageIO.read(new File(qrCodePath)));
- //在背景图片中添加入需要写入的信息,例如:扫描下方二维码,欢迎大家添加我的淘宝返利机器人,居家必备,省钱购物专属小秘书!
- //String message = "扫描下方二维码,欢迎大家添加我的淘宝返利机器人,居家必备,省钱购物专属小秘书!";
- Graphics2D g = background.createGraphics();
- //在背景图片上添加二维码图片
- g.drawImage(qrCode, 320, 330, qrCode.getWidth(), qrCode.getHeight(), null);
- g.dispose();
- ImageIO.write(background, "jpg", new File(outPutPath));
- File outPutPath_file = new File(outPutPath);
- // DpiHandleHelper.handleDpi(outPutPath_file,300,300);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
- public String overlapImage2(String backgroundPath, String qrCodePath, String yrCodePath, String cName, String eName, String orgName, String duty, String idNm, String outPutPath) {
- try {
- //设置图片大小
- BufferedImage background = resizeImage(1075, 709, ImageIO.read(new File(backgroundPath)));
- BufferedImage qrCode = resizeImage(150, 150, ImageIO.read(new File(qrCodePath)));
- BufferedImage yrCode = resizeImage(196, 276, ImageIO.read(new File(yrCodePath)));
- //在背景图片中添加入需要写入的信息,例如:扫描下方二维码,欢迎大家添加我的淘宝返利机器人,居家必备,省钱购物专属小秘书!
- //String message = "扫描下方二维码,欢迎大家添加我的淘宝返利机器人,居家必备,省钱购物专属小秘书!";
- FontRenderContext frc = new FontRenderContext(null, true, true);
- Font font = new Font("微软雅黑", Font.BOLD, 40);
- Rectangle2D r2D = font.getStringBounds(cName, frc);
- int rWidth = (int) Math.round(r2D.getWidth());
- int rX = (int) Math.round(r2D.getX());
- Rectangle r = new Rectangle(0, 0, 775, 709);
- int a = (r.width / 2) - (rWidth / 2) - rX;
- Graphics2D g = background.createGraphics();
- g.setColor(Color.BLACK);
- g.setFont(font);
- g.drawString(cName, r.x + a, 273);
- FontRenderContext frc1 = new FontRenderContext(null, true, true);
- Font font1 = new Font("Arial", Font.BOLD, 40);
- Rectangle2D r2D1 = font1.getStringBounds(eName, frc1);
- int rWidth1 = (int) Math.round(r2D1.getWidth());
- int rX1 = (int) Math.round(r2D1.getX());
- Rectangle r1 = new Rectangle(0, 0, 775, 709);
- int a1 = (r1.width / 2) - (rWidth1 / 2) - rX1;
- g.setFont(font1);
- g.drawString(eName, r1.x + a1, 320);
- g.setFont(getFont(orgName, "宋体", 28));
- g.drawString(orgName, 350, 396);
- g.setFont(getFont(duty, "宋体", 28));
- g.drawString(duty, 350, 451);
- g.setFont(getFont(idNm, "Arial", 28));
- g.drawString(idNm, 350, 508);
- //在背景图片上添加二维码图片
- g.drawImage(qrCode, 835, 395, qrCode.getWidth(), qrCode.getHeight(), null);
- g.drawImage(yrCode, 808, 106, yrCode.getWidth(), yrCode.getHeight(), null);
- g.dispose();
- ImageIO.write(background, "jpg", new File(outPutPath));
- File outPutPath_file = new File(outPutPath);
- // DpiHandleHelper.handleDpi(outPutPath_file,300,300);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
- public String overlapImage3(String backgroundPath, String qrCodePath, String outPutPath) {
- try {
- //设置图片大小
- BufferedImage background = resizeImage(1075, 709, ImageIO.read(new File(backgroundPath)));
- BufferedImage qrCode = resizeImage(200, 200, ImageIO.read(new File(qrCodePath)));
- //在背景图片中添加入需要写入的信息,例如:扫描下方二维码,欢迎大家添加我的淘宝返利机器人,居家必备,省钱购物专属小秘书!
- //String message = "扫描下方二维码,欢迎大家添加我的淘宝返利机器人,居家必备,省钱购物专属小秘书!";
- Graphics2D g = background.createGraphics();
- //在背景图片上添加二维码图片
- g.drawImage(qrCode, 795, 330, qrCode.getWidth(), qrCode.getHeight(), null);
- g.dispose();
- ImageIO.write(background, "jpg", new File(outPutPath));
- File outPutPath_file = new File(outPutPath);
- // DpiHandleHelper.handleDpi(outPutPath_file,300,300);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
- public String getFiles(String path, String name) {
- String fileName = "";
- File file = new File(path);
- // 如果这个路径是文件夹
- if (file.isDirectory()) {
- // 获取路径下的所有文件
- File[] files = file.listFiles();
- for (int i = 0; i < files.length; i++) {
- File fl = files[i];
- // 如果还是文件夹 递归获取里面的文件 文件夹
- if (files[i].isDirectory()) {
- fileName = getFiles(files[i].getPath(), name);
- if (org.apache.commons.lang3.StringUtils.isNotEmpty(fileName)) {
- break;
- }
- } else {
- if (fl.getPath().contains(name)) {
- fileName = fl.getPath();
- break;
- }
- }
- }
- } else {
- if (file.getPath().contains(name)) {
- fileName = file.getPath();
- }
- }
- return fileName;
- }
- public BufferedImage resizeImage(int x, int y, BufferedImage bfi) {
- BufferedImage bufferedImage = new BufferedImage(x, y, BufferedImage.TYPE_INT_RGB);
- bufferedImage.getGraphics().drawImage(
- bfi.getScaledInstance(x, y, Image.SCALE_SMOOTH), 0, 0, null);
- return bufferedImage;
- }
- @Override
- public int changePassword(String id, String password, String newPassword) {
- BisInspAllRlationPers user = bisInspAllRlationPersDao.get(id);
- if (null == user || StringUtils.isBlank(user.getGuid())) {
- //用户不存在
- return 0;
- }
- if (!password.equals(user.getPwd())) {
- //原密码错误
- return 2;
- }
- user.setPwd(newPassword);
- bisInspAllRlationPersDao.update(user);
- return 1;
- }
- @Override
- public void updateUser(List<UserRoleParam> userRoleParams, UserRoleParam param) {
- logger.info(" start delete user role ");
- userRoleDao.deleteByUserId(param.getUserId());
- logger.info("delete user role ");
- /*if (null != userRoleParams && userRoleParams.size() > 0) {
- userRoleDao.addList(userRoleParams);
- }*/
- logger.info(" start insert user role ");
- if (null != userRoleParams && userRoleParams.size() > 0) {
- for (UserRoleParam userRoleParam : userRoleParams) {
- UserRole userRole = new UserRole();
- userRole.setUserId(userRoleParam.getUserId());
- userRole.setRoleId(userRoleParam.getRoleId());
- userRoleDao.insert(userRole);
- }
- }
- logger.info(" end insert user role ");
- }
- @Override
- public int selectCountOnlinePers(String sttm, String entm, String province) {
- return bisInspAllRlationPersDao.selectCountOnlinePers(sttm, entm, province);
- }
- @Override
- public List<HashMap<String, Object>> selectOnlinePers(String sttm, String entm, String orgId) {
- return bisInspAllRlationPersDao.selectOnlinePers(sttm, entm, orgId);
- }
- @Override
- public GroupLeaderDto getLeaderByGroup(GroupLeaderParam groupLeaderParam) {
- return this.bisInspAllRlationPersDao.getLeaderByGroup(groupLeaderParam);
- }
- @Override
- public BisInspAllRlationPers getById(String id) {
- return getOne(id);
- }
- @Override
- public PageInfo<PersListDto> findPersData(BisInspAllRlationPersParam p) {
- PageHelper.startPage(p);
- List<PersListDto> list = this.bisInspAllRlationPersDao.findPersData(p);
- PageInfo<PersListDto> pageInfo = new PageInfo(list);
- return pageInfo;
- }
- @Override
- public PageInfo<PersListDto> listByCurUser(UserListByCurUserParam param, String addvcd) throws Exception {
- BisInspAllRlationPers per = bisInspAllRlationPersDao.get(param.getCurUserId());
- if (per == null) {
- throw new Exception("此用户不存在:" + param.getCurUserId());
- }
- if (per.getOwnerSystem() == null) {
- throw new Exception("用户所属系统不正确:" + per.getOwnerSystem());
- }
- List<String> systemList = new ArrayList<>();
- if (!SystemFlagEnum.DC_ALL.getValue().equals(per.getOwnerSystem())) {
- systemList.add(per.getOwnerSystem());
- }
- PageHelper.startPage(param.getPageNum(), param.getPageSize());
- List<PersListDto> list = bisInspAllRlationPersDao.listByCurUser(param.getPersName(), systemList,
- param.getPhoneIsNull(), param.getMobilenumb(), param.getOrgNm(), param.getOrgId(), param.getProvince(), param.getDpnm(), param.getPlanDpId());
- for (PersListDto persListDto : list) {
- persListDto.setPwd("***");
- if (StringUtils.isNotBlank(persListDto.getOrgNames())) {
- persListDto.setOrgNm(persListDto.getOrgNames());
- if (StringUtils.isNotBlank(persListDto.getPlanDpId()) && "37".equals(addvcd)) {
- BisInspPlanDp bisInspPlanDp = bisInspPlanDpService.get(persListDto.getPlanDpId());
- if (bisInspPlanDp != null) {
- persListDto.setPlanDpNm(bisInspPlanDp.getDpName());
- }
- }
- }
- //手机号脱敏处理
- persListDto.setMobilenumb(UserMsgSectrityUtils.blurPhoneNotExc(persListDto.getMobilenumb()));
- }
- return new PageInfo<PersListDto>(list);
- }
- @Override
- public PageInfo<PersListDto> listByCurUser(UserListByCurUserParam param) throws Exception {
- BisInspAllRlationPers per = bisInspAllRlationPersDao.get(param.getCurUserId());
- if (per == null) {
- throw new Exception("此用户不存在:" + param.getCurUserId());
- }
- if (per.getOwnerSystem() == null) {
- throw new Exception("用户所属系统不正确:" + per.getOwnerSystem());
- }
- List<String> systemList = new ArrayList<>();
- if (!SystemFlagEnum.DC_ALL.getValue().equals(per.getOwnerSystem())) {
- systemList.add(per.getOwnerSystem());
- }
- PageHelper.startPage(param.getPageNum(), param.getPageSize());
- List<PersListDto> list = bisInspAllRlationPersDao.listByCurUser(param.getPersName(), systemList,
- param.getPhoneIsNull(), param.getMobilenumb(), param.getOrgNm(), param.getOrgId(), param.getProvince(), param.getDpnm(), param.getPlanDpId());
- for (PersListDto persListDto : list) {
- if (StringUtils.isNotBlank(persListDto.getOrgNames())) {
- persListDto.setOrgNm(persListDto.getOrgNames());
- }
- //手机号脱敏处理
- persListDto.setMobilenumb(UserMsgSectrityUtils.blurPhoneNotExc(persListDto.getMobilenumb()));
- }
- return new PageInfo<PersListDto>(list);
- }
- @Override
- public BisInspAllRlationPers getCurUser(String id) {
- return bisInspAllRlationPersDao.get(id);
- }
- @Autowired
- private BisInspPersOrgDao inspPersOrgDao;
- @Override
- public void updatePersState(String guid, String isEnable) {
- this.bisInspAllRlationPersDao.updatePersState(guid, isEnable);
- }
- @Override
- public void updateUserNode(String guid, String persType, String orgId) {
- //修改用户类型
- BisInspAllRlationPers pers = bisInspAllRlationPersDao.get(guid);
- if (orgId.equals(pers.getOrgId())) {
- this.bisInspAllRlationPersDao.updatePersTypeById(guid, persType);
- }
- BisInspPersOrgParam persOrgParam = new BisInspPersOrgParam();
- persOrgParam.setPersId(guid);
- persOrgParam.setOrgId(orgId);
- BisInspPersOrg inspPersOrg = inspPersOrgDao.getBy(persOrgParam);
- if (inspPersOrg == null) {
- inspPersOrg = new BisInspPersOrg();
- inspPersOrg.setOrgId(orgId);
- inspPersOrg.setUserType(persType);
- inspPersOrg.setPersId(guid);
- inspPersOrgDao.insert(inspPersOrg);
- } else {
- inspPersOrg.setOrgId(orgId);
- inspPersOrg.setUserType(persType);
- inspPersOrg.setPersId(guid);
- inspPersOrgDao.update(inspPersOrg);
- }
- //根据用户id获取用户信息
- //获取人员所属类型
- List<PersTypeDto> persTypeByPersid = this.supervisionPlanDao.getPersTypeByPersid(guid, orgId, inspOrgService.getProvince(orgId));
- if (persTypeByPersid.size() > 0) {
- if ("1".equals(persType) || "2".equals(persType)) {
- //管理员或者机构领导
- for (PersTypeDto persTypeDto : persTypeByPersid) {
- String s = persTypeDto.getId() + orgId;
- OlBisInspOrg bisInspOrg = inspOrgService.get(orgId);
- if ("027".equals(orgId) || "029".equals(orgId) || "041".equals(orgId)) {
- s = persTypeDto.getId();
- }
- //查询是否存在该节点
- BisInspAllDto bisInspAllDto = this.bisInspAllRlationPersDao.getNodeInfo(s);
- if (bisInspAllDto != null) {
- //查询是否已经建立关系
- BisInspAllRlation bisInspAllRlation = null;
- if (!bisInspOrg.getRlcode().startsWith(AdCodeLabel.START_PARENT_ADCODE)) {
- bisInspAllRlation = bisInspAllRlationPersDao.getRelationData(guid, s, orgId, bisInspOrg.getRlcode());
- } else {
- bisInspAllRlation = bisInspAllRlationPersDao.getRelationData(guid, s, "", "");
- }
- if (bisInspAllRlation == null) {
- String type = Integer.parseInt(s.substring(0, 3)) + "";
- this.bisInspAllRlationPersDao.insertRelation(guid, s, orgId, bisInspOrg.getRlcode(), type);
- }
- }
- }
- }
- }
- }
- @Autowired
- private BisInspOrgDao bisInspOrgDao;
- @Autowired
- private OlBisInspOrgService inspOrgService;
- @Autowired
- private BisInspPersOrgService persOrgService;
- // 返回一个用户信息
- @Override
- public BisInspAllRlationPers getOne(String persId) {
- BisInspAllRlationPers allRlationPers = bisInspAllRlationPersDao.get(persId);
- if (null != allRlationPers && StringUtils.isNotBlank(allRlationPers.getOrgId())) {
- BisInspOrg inspOrg = bisInspOrgDao.get(allRlationPers.getOrgId());
- if (inspOrg == null) {
- return allRlationPers;
- }
- allRlationPers.setDefaultOrg(inspOrg);
- BisInspOrgParam inspOrgParam = new BisInspOrgParam();
- inspOrgParam.setPersId(allRlationPers.getGuid());
- List<BisInspOrg> inspOrgList = bisInspOrgDao.findPersOrgList(inspOrgParam);
- if (inspOrgList != null && !inspOrgList.isEmpty()) {
- allRlationPers.setAllOrg(inspOrgList);
- } else {
- inspOrgList = new ArrayList<>();
- inspOrgList.add(inspOrg);
- allRlationPers.setAllOrg(inspOrgList);
- BisInspPersOrg inspPersOrg = new BisInspPersOrg();
- inspPersOrg.setPersId(allRlationPers.getGuid());
- inspPersOrg.setOrgId(allRlationPers.getOrgId());
- inspPersOrg.setUserType(allRlationPers.getPersType());
- BisInspPersOrgParam inspPersOrgParam = new BisInspPersOrgParam();
- inspPersOrgParam.setOrgId(allRlationPers.getOrgId());
- inspPersOrgParam.setPersId(allRlationPers.getGuid());
- BisInspPersOrg persOrg = persOrgService.getBy(inspPersOrgParam);
- if (persOrg == null) {
- persOrgService.insert(inspPersOrg);
- } else {
- allRlationPers.setPersType(persOrg.getUserType());
- allRlationPers.setOrgId(persOrg.getOrgId());
- }
- }
- }
- // allRlationPers.setMobilenumb(UserMsgSectrityUtils.blurPhone(allRlationPers.getMobilenumb()));
- return allRlationPers;
- }
- @Override
- public int insertUser(BisInspAllRlationPers bisInspAllRlationPers) {
- BisInspPersOrg persOrg = new BisInspPersOrg();
- persOrg.setPersId(bisInspAllRlationPers.getGuid());
- persOrg.setOrgId(bisInspAllRlationPers.getOrgId());
- OlBisInspOrg olBisInspOrg = inspOrgService.get(bisInspAllRlationPers.getOrgId());
- persOrg.setUserType(bisInspAllRlationPers.getPersType());
- inspPersOrgDao.insert(persOrg);
- bisInspAllRlationPers.setOrgNm(olBisInspOrg.getOrgNm());
- return bisInspAllRlationPersDao.insert(bisInspAllRlationPers);
- }
- @Override
- public int updateData(BisInspAllRlationPers bisInspAllRlationPers) {
- BisInspPersOrgParam inspPersOrgParam = new BisInspPersOrgParam();
- inspPersOrgParam.setOrgId(bisInspAllRlationPers.getOrgId());
- inspPersOrgParam.setPersId(bisInspAllRlationPers.getGuid());
- BisInspPersOrg persOrg = inspPersOrgDao.getBy(inspPersOrgParam);
- if (persOrg != null) {
- persOrg.setUserType(bisInspAllRlationPers.getPersType());
- if (persOrg.getUserType() != null) {
- inspPersOrgDao.update(persOrg);
- }
- } else {
- persOrg = new BisInspPersOrg();
- persOrg.setUserType(bisInspAllRlationPers.getPersType() == null ? "3" : bisInspAllRlationPers.getPersType());
- persOrg.setPersId(bisInspAllRlationPers.getGuid());
- persOrg.setOrgId(bisInspAllRlationPers.getOrgId());
- inspPersOrgDao.insert(persOrg);
- }
- return bisInspAllRlationPersDao.update(bisInspAllRlationPers);
- }
- @Override
- public int selectCount(BisInspAllRlationPersParam bisInspAllRlationPersParam) {
- return bisInspAllRlationPersDao.selectCount(bisInspAllRlationPersParam);
- }
- @Override
- public LoginUser getLoginUser(BisInspAllRlationPers pers) {
- LoginUser loginUser = new LoginUser();
- loginUser.setMobile(UserMsgSectrityUtils.blurPhone(pers.getMobilenumb()));
- loginUser.setPersId(pers.getGuid());
- loginUser.setPersName(pers.getPersName());
- loginUser.setpType(StringUtils.isBlank(pers.getPersType()) ? "3" : pers.getPersType());
- return loginUser;
- }
- @Override
- public void sendChannel(String token, BisInspAllRlationPers bisInspAllRlationPers, HttpServletRequest request, int plusFlag) {
- Map<String, String> userMap = new HashMap<>();
- userMap.put("id", bisInspAllRlationPers.getGuid());
- userMap.put("userName", bisInspAllRlationPers.getPersName());
- userMap.put("userNum", bisInspAllRlationPers.getMobilenumb());
- userMap.put("password", "Jinshui@433@440");
- userMap.put("persType", bisInspAllRlationPers.getPersType());
- JSONObject jsonObject = JSONObject.fromObject(userMap);
- redisTemplate.convertAndSend(CommonLabel.ACTIVITI, jsonObject);
- userMap.clear();
- //向公司发送实时人员登录信息
- userMap.put("userName", bisInspAllRlationPers.getPersName());
- userMap.put("phone", bisInspAllRlationPers.getMobilenumb());
- userMap.put("login", plusFlag + "");
- OlBisInspOrg org = olBisInspOrgDao.get(bisInspAllRlationPers.getOrgId());
- Optional.ofNullable(org).orElseThrow(() -> new CheckException("用户的机构ID异常、未获取到对应机构"));
- userMap.put("orgId", bisInspAllRlationPers.getOrgId());
- userMap.put("orgNm", org.getOrgNm());
- userMap.put("orgAdCode", org.getAdCode());
- userMap.put("sysName", CommonLabel.SYS_NAME);
- userMap.put("id", token);//用token防止数据重复
- userMap.put("empire", JWTTokenUtil.maxAge + "");//失效时间long类型
- try {
- userMap.put("workUrl", workUrl);
- InetAddress ia = InetAddress.getLocalHost();
- String host = ia.getHostName();
- userMap.put("appmodel", host);
- if (StringUtils.isNotBlank(request.getHeader("source"))) {
- userMap.put("app", plusFlag + "");
- userMap.put("appmodel", request.getHeader("source"));
- } else {
- userMap.put("pc", plusFlag + "");
- userMap.put("appmodel", host);
- }
- userMap.put("ipAddr", IPUtils.getIpAddr(request));
- } catch (UnknownHostException e) {
- userMap.put("ipAddr", "IP_FAIL");
- }
- jsonObject = JSONObject.fromObject(userMap);
- redisTemplate.convertAndSend(CommonLabel.SEND_TO_CENTER, jsonObject);
- }
- @Autowired
- private BisInspAllRlationDao bisInspAllRlationDao;
- @Override
- public PageInfo<PersListDto> listByMap(Map<String, Object> paramMap) {
- String adCode = MapUtils.getString(paramMap, "adCode");
- if (StringUtils.isNotBlank(adCode)) {
- paramMap.put("adCode", AdLevelUtil.getAddvcd(adCode));
- }
- PageHelper.startPage(MapUtils.getIntValue(paramMap, "pageNum"), MapUtils.getIntValue(paramMap, "pageSize"));
- StatisticalUtil.setDate(paramMap);
- List<PersListDto> persList = bisInspAllRlationPersDao.listByMap(paramMap);
- // 循环 添加 所在组名
- persList.forEach(per -> {
- if (per.getDcNum().intValue() > 0) {
- // 当前人的督查次数大于0
- BisInspAllRlationParam bisInspAllRlationParam = Builder.of(BisInspAllRlationParam::new)
- .with(BisInspAllRlationParam::setPersid, per.getGuid())
- .with(BisInspAllRlationParam::setpType, MapUtils.getString(paramMap, "objType"))
- .with(BisInspAllRlationParam::setOrgId, MapUtils.getString(paramMap, "orgId"))
- .with(BisInspAllRlationParam::setSttm, MapUtils.getString(paramMap, "sttm"))
- .with(BisInspAllRlationParam::setEntm, MapUtils.getString(paramMap, "entm"))
- .build();
- Set<String> pnmArr = bisInspAllRlationDao.getPnmByPersid(bisInspAllRlationParam);
- per.setGroupName(String.join("、", pnmArr));
- //添加类别
- Set<String> objNameArr = bisInspAllRlationDao.getObjByPersid(bisInspAllRlationParam);
- per.setObjName(String.join("、", objNameArr));
- PersPositionLatest persPositionLatest = persPositionLatestDao.get(per.getGuid());
- Optional.ofNullable(persPositionLatest).ifPresent(perLatest -> {
- per.setCenterXGd(perLatest.getLon() == null ? "" : String.valueOf(perLatest.getLon()));
- per.setCenterYGd(perLatest.getLat() == null ? "" : String.valueOf(perLatest.getLat()));
- per.setState(DateUtils.getToday("yyyy-MM-dd")
- .equals(DateUtils.Date2Str(perLatest.getOperateTime(), "yyyy-MM-dd")) ? "1" : "0");
- });
- //获取人员分配的组
- String dcWork = "";
- List<BisInspAll> bisInspAlls = bisInspAllService.getPersDcWork(per.getGuid());
- for (BisInspAll bisInspAll : bisInspAlls) {
- if (bisInspAll.getSttm() == null || bisInspAll.getEntm() == null) {
- dcWork += " 在组" + bisInspAll.getPnm() + " 中担任:" + getName(bisInspAll.getPertype()) + "\r\n";
- } else {
- dcWork += DateUtils.Date2Str(bisInspAll.getSttm()) + "至" + DateUtils.Date2Str(bisInspAll.getEntm()) + " 在组" + bisInspAll.getPnm() + " 中担任:" + getName(bisInspAll.getPertype()) + "\r\n";
- }
- }
- if (dcWork.length() > 0) {
- dcWork = dcWork.substring(0, dcWork.length() - 1);
- }
- per.setDcWork(dcWork);
- }
- });
- return new PageInfo<>(persList);
- }
- public String getName(String perType) {
- String name = "";
- if (perType.equals("1")) {
- name = "组长";
- } else if (perType.equals("2")) {
- name = "组员";
- } else if (perType.equals("3")) {
- name = "专家";
- } else if (perType.equals("3")) {
- name = "联络员";
- }
- return name;
- }
- @Override
- public HashMap updateListUsers(AddRlationPersDto addRlationPersDto) {
- HashMap<Object, Object> map = new HashMap<>();
- ArrayList<UserRoleParam> userRoleParams = new ArrayList<>();
- BisInspAllRlationPers pers = new BisInspAllRlationPers();
- int allCount = 0, failCount = 0;
- List<String> mobilenumbList = new ArrayList<>();
- for (BisInspAllRlationPers bisInspAllRlationPers : addRlationPersDto.getListRlationPers()) {
- allCount++;
- if (StringUtils.isBlank(bisInspAllRlationPers.getGuid())) {
- bisInspAllRlationPers.setRoleIds(addRlationPersDto.getRoleIds());
- pers = inserts(bisInspAllRlationPers);
- if (pers == null) {
- failCount++;
- mobilenumbList.add(bisInspAllRlationPers.getMobilenumb());
- }
- }
- if (addRlationPersDto.getRoleIds().size() > 0 && addRlationPersDto.getRoleIds() != null && pers != null) {
- for (String roleId : addRlationPersDto.getRoleIds()) {
- UserRoleParam userRoleParam = new UserRoleParam();
- userRoleParam.setUserId(bisInspAllRlationPers.getGuid());
- userRoleParam.setRoleId(roleId);
- userRoleParams.add(userRoleParam);
- }
- }
- if (pers != null) {
- BisInspPersOrg bisInspPersOrg = new BisInspPersOrg();
- bisInspPersOrg.setPersId(bisInspAllRlationPers.getGuid());
- bisInspPersOrg.setOrgId(bisInspAllRlationPers.getOrgId());
- bisInspPersOrg.setUserType(bisInspAllRlationPers.getPersType());
- bisInspPersOrgService.insert(bisInspPersOrg);
- }
- }
- updateUserRole(userRoleParams);
- map.put("all", allCount);
- map.put("success", allCount - failCount);
- map.put("fail", failCount);
- map.put("failMobilenumb", mobilenumbList);
- return map;
- }
- @Override
- public void updatePassword(BisInspAllRlationPers bisInspAllRlationPers) {
- bisInspAllRlationPersDao.updatePassword(bisInspAllRlationPers);
- }
- private void updateUserRole(ArrayList<UserRoleParam> userRoleParams) {
- if (userRoleParams != null && userRoleParams.size() > 0) {
- userRoleDao.deleteList(userRoleParams);
- userRoleDao.addList(userRoleParams);
- }
- }
- public BisInspAllRlationPers inserts(BisInspAllRlationPers bisInspAllRlationPers) {
- String uuid = UuidUtil.uuid();
- bisInspAllRlationPers.setGuid(uuid);
- Assert.notNull(bisInspAllRlationPers.getPersName(), "人员姓名为必填参数");
- Assert.notNull(bisInspAllRlationPers.getOwnerSystem(), "所属系统为必填参数");
- BisInspAllRlationPersParam param = new BisInspAllRlationPersParam();
- param.setMobilenumb(bisInspAllRlationPers.getMobilenumb());
- List<BisInspAllRlationPers> list = findPage(param);
- if (list != null && list.size() > 0) {
- return null;
- }
- bisInspAllRlationPersDao.insert(bisInspAllRlationPers);
- return bisInspAllRlationPers;
- }
- }
|