Commit 95709d18 by manxiaoqiang

合同

parent 424a97b7
package common.controller;
import common.model.Contract;
import common.model.Menu;
import common.model.User;
import common.service.ContractService;
import common.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import security.annotation.CurrentAccount;
import util.ResultModel;
import java.util.List;
/**
* Created by mxq on 17/12/21.
* 优先测试账号查询
*/
@Controller
@RequestMapping("{platform}/contract")
public class ContractController {
@Autowired
private ContractService service;
@RequestMapping(value = "find", method = RequestMethod.GET)
@ResponseBody
public ResultModel findAll(@CurrentAccount User loginAccount, @RequestParam String startDate) {
return ResultModel.OK(service.findAll(startDate));
}
@RequestMapping(value = "checkAccount", method = RequestMethod.GET)
@ResponseBody
public ResultModel checkAccount(@CurrentAccount User loginAccount, @RequestParam String email) {
return ResultModel.OK(service.checkAccount(email));
}
@RequestMapping(value = "find/body", method = RequestMethod.GET)
@ResponseBody
public ResultModel findBody(@CurrentAccount User loginAccount) {
return ResultModel.OK(service.findBody());
}
@RequestMapping(value = "find/code", method = RequestMethod.GET)
@ResponseBody
public ResultModel findCode(@CurrentAccount User loginAccount, @RequestParam String code) {
return ResultModel.OK(service.getContractCode(code));
}
@RequestMapping(value = "find/pricelevel", method = RequestMethod.GET)
@ResponseBody
public ResultModel findPricelevel(@CurrentAccount User loginAccount) {
return ResultModel.OK(service.findSetmeal());
}
@RequestMapping(value = "find/rebat", method = RequestMethod.GET)
@ResponseBody
public ResultModel rebat(@CurrentAccount User loginAccount, @RequestParam String product,
@RequestParam Integer level, @RequestParam Long money) {
return ResultModel.OK(service.getRebat(product, level, money));
}
@RequestMapping(value = "find/sale", method = RequestMethod.GET)
@ResponseBody
public ResultModel rebat(@CurrentAccount User loginAccount) {
return ResultModel.OK(service.getSales());
}
@RequestMapping(value = "create", method = RequestMethod.POST)
@ResponseBody
public ResultModel create(@CurrentAccount User loginAccount, @RequestBody Contract contract) {
return ResultModel.OK(service.create(loginAccount, contract));
}
}
package common.controller;
import common.model.Menu;
import common.model.User;
import common.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import security.annotation.CurrentAccount;
import util.ResultModel;
import java.util.List;
/**
* Created by mxq on 17/12/21.
* 优先测试账号查询
*/
@Controller
@RequestMapping("saleauth")
public class SaleAuthController {
@Autowired
private MenuService menuService;
@RequestMapping(value = "find", method = RequestMethod.GET)
@ResponseBody
public ResultModel findAll(@CurrentAccount User loginAccount) {
List<Menu> menus = menuService.listAll();
return ResultModel.OK(menus);
}
}
package common.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Transient;
import java.util.Date;
/**
* Created by mxq on 2018/1/16.
*/
@Entity
public class Contract {
private Long id;
private String product;
private String myBodyName;
private String myBodyCode;
private String customerBody;
private String email;
private String contractCode;
private String contractType;
private String startDate;
private String endDate;
private Long priceLevel;
private Long money;
private Double rebate;
private Long sale;
private String platform;
private String status;
private String saleName;
private String priceLevelName;
private Long modifyAccount;
private Long createAccount;
private Date modifyTime;
private Date createTime;
private String ds;
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getProduct() {
return product;
}
public void setProduct(String product) {
this.product = product;
}
public String getMyBodyName() {
return myBodyName;
}
public void setMyBodyName(String myBodyName) {
this.myBodyName = myBodyName;
}
public String getMyBodyCode() {
return myBodyCode;
}
public void setMyBodyCode(String myBodyCode) {
this.myBodyCode = myBodyCode;
}
public String getCustomerBody() {
return customerBody;
}
public void setCustomerBody(String customerBody) {
this.customerBody = customerBody;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getContractCode() {
return contractCode;
}
public void setContractCode(String contractCode) {
this.contractCode = contractCode;
}
public String getContractType() {
return contractType;
}
public void setContractType(String contractType) {
this.contractType = contractType;
}
public String getStartDate() {
return startDate;
}
public void setStartDate(String stratDate) {
this.startDate = stratDate;
}
public String getEndDate() {
return endDate;
}
public void setEndDate(String endDate) {
this.endDate = endDate;
}
public Long getPriceLevel() {
return priceLevel;
}
public void setPriceLevel(Long priceLevel) {
this.priceLevel = priceLevel;
}
public Long getMoney() {
return money;
}
public void setMoney(Long money) {
this.money = money;
}
public Double getRebate() {
return rebate;
}
public void setRebate(Double rebate) {
this.rebate = rebate;
}
public Long getSale() {
return sale;
}
public void setSale(Long sale) {
this.sale = sale;
}
public String getPlatform() {
return platform;
}
public void setPlatform(String platform) {
this.platform = platform;
}
public Long getModifyAccount() {
return modifyAccount;
}
public void setModifyAccount(Long modifyAccount) {
this.modifyAccount = modifyAccount;
}
public Long getCreateAccount() {
return createAccount;
}
public void setCreateAccount(Long createAccount) {
this.createAccount = createAccount;
}
public Date getModifyTime() {
return modifyTime;
}
public void setModifyTime(Date modifyTime) {
this.modifyTime = modifyTime;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public String getDs() {
return ds;
}
public void setDs(String ds) {
this.ds = ds;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
@Transient
public String getSaleName() {
return saleName;
}
public void setSaleName(String saleName) {
this.saleName = saleName;
}
@Transient
public String getPriceLevelName() {
return priceLevelName;
}
public void setPriceLevelName(String priceLevelName) {
this.priceLevelName = priceLevelName;
}
@Override
public String toString() {
return "Contract{" +
"id=" + id +
", product='" + product + '\'' +
", myBodyName='" + myBodyName + '\'' +
", myBodyCode='" + myBodyCode + '\'' +
", customerBody='" + customerBody + '\'' +
", email='" + email + '\'' +
", contractCode='" + contractCode + '\'' +
", contractType='" + contractType + '\'' +
", startDate='" + startDate + '\'' +
", endDate='" + endDate + '\'' +
", priceLevel=" + priceLevel +
", money=" + money +
", rebate=" + rebate +
", sale=" + sale +
", platform='" + platform + '\'' +
", status='" + status + '\'' +
", modifyAccount=" + modifyAccount +
", createAccount=" + createAccount +
", modifyTime=" + modifyTime +
", createTime=" + createTime +
", ds='" + ds + '\'' +
'}';
}
}
package common.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
/**
* Created by mxq on 2018/1/17.
*/
@Entity
public class ContractBody {
private Long id;
private String name;
private String code;
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
}
package common.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.criteria.CriteriaBuilder;
/**
* Created by mxq on 2018/1/17.
*/
@Entity
public class PriceLevelMoney {
private Long id;
private Integer pricelevel;
private String product;
private Long money;
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Integer getPricelevel() {
return pricelevel;
}
public void setPricelevel(Integer pricelevel) {
this.pricelevel = pricelevel;
}
public String getProduct() {
return product;
}
public void setProduct(String product) {
this.product = product;
}
public Long getMoney() {
return money;
}
public void setMoney(Long money) {
this.money = money;
}
}
package common.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
/**
* Created by mxq on 2018/1/16.
*/
@Entity
public class SaleAuth {
private Long id;
private String name;
private Integer roleLevel;
private Long parent;
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getRoleLevel() {
return roleLevel;
}
public void setRoleLevel(Integer roleLevel) {
this.roleLevel = roleLevel;
}
public Long getParent() {
return parent;
}
public void setParent(Long parent) {
this.parent = parent;
}
public SaleAuth() {
}
public SaleAuth(Long id, String name, Integer roleLevel, Long parent) {
this.id = id;
this.name = name;
this.roleLevel = roleLevel;
this.parent = parent;
}
@Override
public String toString() {
return "SaleAuth{" +
"id=" + id +
", name='" + name + '\'' +
", roleLevel=" + roleLevel +
", parent=" + parent +
'}';
}
}
......@@ -21,4 +21,7 @@ public interface Account4WebRepository extends JpaRepository<Account4Web, Long>
@Query(value = "SELECT * from account4web where status = '已过期' or status = '流量用尽'", nativeQuery = true)
List<Account4Web> findPast();
@Query(value = "SELECT * from account4web where email = ?1", nativeQuery = true)
Account4Web findByEmail(String email);
}
package common.repository;
import common.model.Contract;
import common.model.ContractBody;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.transaction.annotation.Transactional;
@Transactional
public interface ContractBodyRepository extends JpaRepository<ContractBody, Long> {
}
package common.repository;
import common.model.Contract;
import common.model.Role;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigInteger;
import java.util.List;
@Transactional
public interface ContractRepository extends JpaRepository<Contract, Long> {
@Query(value="select count(*) from contract where ds = ?1",nativeQuery=true)
BigInteger countNumByDs(String ds);
@Query(value="select count(*) from contract where email = ?1",nativeQuery=true)
BigInteger countNumByEmail(String email);
@Query(value="select * from contract where start_date = ?1 order by start_date desc",nativeQuery=true)
List<Contract> findByDs(String ds);
}
package common.repository;
import common.model.Contract;
import common.model.PriceLevelMoney;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
@Transactional
public interface PriceLevelMoneyRepository extends JpaRepository<PriceLevelMoney, Long> {
@Query(value="select * from price_level_money where product = ?1 and pricelevel = ?2",nativeQuery=true)
PriceLevelMoney getOne(String product, Integer level);
}
package common.repository;
import common.model.Auth;
import common.model.SaleAuth;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.transaction.annotation.Transactional;
@Transactional
public interface SaleAuthRepository extends JpaRepository<SaleAuth, Long> {
}
......@@ -23,4 +23,10 @@ public interface UserRepository extends JpaRepository<User, Long> {
@Query(value="select * from user where email = ?1 and del_flag is not true",nativeQuery=true)
User login(String email);
@Query(value="select * from user where del_flag is not true and (role = 2 or role = 3)",nativeQuery=true)
List<User> findSales();
@Query(value="select * from user where role = 2 or role = 3",nativeQuery=true)
List<User> findAllSales();
}
package common.service;
import common.model.Contract;
import common.model.ContractBody;
import common.model.User;
import tkio.model.PackageType;
import java.util.List;
import java.util.Map;
/**
* Created by mxq on 2018/1/16.
*/
public interface ContractService {
Map<String, Object> checkAccount(String email);
List<ContractBody> findBody();
String getContractCode(String code);
List<PackageType> findSetmeal();
Double getRebat(String product, Integer level, Long money);
List<User> getSales();
Contract create(User loginUser, Contract resource);
Contract update(User loginUser, Contract resource);
List<Contract> findAll(String ds);
}
package common.service;
/**
* Created by mxq on 2018/1/16.
*/
public interface SaleAuthService {
}
package common.service.impl;
import com.google.api.ads.adwords.lib.AdWordsProductFrameworkModule;
import common.model.*;
import common.repository.*;
import common.service.ContractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tkio.model.PackageType;
import tkio.repository.PackageTypeRepository;
import util.DateUtil;
import util.ValidateUtil;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by mxq on 2018/1/16.
*/
@Service
public class ContractServiceImpl implements ContractService{
@Autowired
ContractRepository contractRepository;
@Autowired
ContractBodyRepository contractBodyRepository;
@Autowired
Account4WebRepository account4WebRepository;
@Autowired
PackageTypeRepository packageTypeRepository;
@Autowired
PriceLevelMoneyRepository priceLevelMoneyRepository;
@Autowired
UserRepository userRepository;
@Override
public Map<String, Object> checkAccount(String email) {
Map<String, Object> map = new HashMap<>();
Account4Web account4Web = account4WebRepository.findByEmail(email);
if(null == account4Web){
map.put("result", 0);
}else{
BigInteger integer = contractRepository.countNumByDs(DateUtil.getBeforeDays(0));
map.put("result", 1);
map.put("company", account4Web.getCompany());
map.put("num", integer.intValue());
}
return map;
}
@Override
public List<ContractBody> findBody() {
return contractBodyRepository.findAll();
}
@Override
public String getContractCode(String code) {
BigInteger integer = contractRepository.countNumByDs(DateUtil.getBeforeDays(0));
String lastCode = "";
if(integer.intValue() < 9){
lastCode = "0" + (integer.intValue() + 1);
}else{
lastCode = "" + (integer.intValue() + 1);
}
String re = code + "-" + DateUtil.getDays2(0) + lastCode;
return re;
}
@Override
public List<PackageType> findSetmeal() {
return packageTypeRepository.findAll();
}
@Override
public Double getRebat(String product, Integer level, Long money) {
PriceLevelMoney levelMoney = priceLevelMoneyRepository.getOne(product, level);
return money * 1.0 / levelMoney.getMoney();
}
@Override
public List<User> getSales() {
return userRepository.findSales();
}
@Override
public Contract create(User loginUser, Contract resource) {
if(DateUtil.getBeforeDays(0).compareTo(resource.getStartDate()) > 0){
resource.setDs(DateUtil.getBeforeDays(0));
resource.setStatus("wait");
}else{
resource.setDs(DateUtil.getBeforeDays(0));
resource.setStatus("executing");
}
return contractRepository.save(resource);
}
@Override
public Contract update(User loginUser, Contract resource) {
return null;
}
@Override
public List<Contract> findAll(String ds) {
List<Contract> result = new ArrayList<>();
List<User> sales = userRepository.findAllSales();
Map<Long, String> saleMap = new HashMap<>();
if(ValidateUtil.isValid(sales)){
for(User s: sales){
saleMap.put(s.getId(), s.getName());
}
}
List<PackageType> typeList = packageTypeRepository.findAll();
Map<Long, String> typeMap = new HashMap<>();
if(ValidateUtil.isValid(typeList)){
for(PackageType s: typeList){
typeMap.put(s.getId(), s.getPackageName());
}
}
List<Contract> contractList = contractRepository.findByDs(ds);
if(ValidateUtil.isValid(contractList)){
for(Contract c : contractList){
c.setSaleName(saleMap.containsKey(c.getSale()) ? saleMap.get(c.getSale()) : "");
c.setPriceLevelName(typeMap.containsKey(c.getPriceLevel()) ? typeMap.get(c.getPriceLevel()) : "");
result.add(c);
}
}
return result;
}
}
......@@ -763,6 +763,15 @@ public class DateUtil {
return beforeDays;
}
public static String getDays2(int days) {
Calendar startCalendar = Calendar.getInstance();
startCalendar.setTime(new Date());
startCalendar.add(Calendar.DAY_OF_YEAR, -days);
String beforeDays = format(startCalendar.getTime(),
C_DATA_PATTON_YYYYMMDD);
return beforeDays;
}
public static String getBeforeDays(String date, int days) {
Calendar startCalendar = Calendar.getInstance();
startCalendar.setTime(parseDate(date));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment